Skip to content

Commit

Permalink
rewrite set cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
taichunmin committed Sep 13, 2024
1 parent abd8c53 commit 6efece8
Show file tree
Hide file tree
Showing 4 changed files with 217 additions and 34 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ jobs:
steps:
- uses: actions/checkout@v2
- id: 'auth'
uses: 'google-github-actions/auth@v0'
uses: 'google-github-actions/auth@v2'
with:
workload_identity_provider: 'projects/391399927959/locations/global/workloadIdentityPools/github-actions-taichunmin-pools/providers/github-actions-provider'
service_account: '[email protected]'
# https://github.com/google-github-actions/setup-gcloud
# https://github.com/google-github-actions/auth#setting-up-workload-identity-federation
- name: 設定 Google Cloud SDK
uses: google-github-actions/setup-gcloud@v0
uses: google-github-actions/setup-gcloud@v2
with:
install_components: 'beta'
- name: 確認 Google Cloud SDK
Expand Down
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ const middlewares = [
}
_.each(OMIT_RES_HEADERS, header => { ctx.res.removeHeader(header) })
const axiosRes = await axios(axiosConfig)

// Rewrite Set-Cookie header
_.update(res, 'headers.set-cookie', cookies => {
const rewriteCookie = cookie => cookie.replaceAll(/; (Secure|Partitioned|SameSite=[^;]+)/imsg, '') + '; SameSite=None; Secure; Partitioned'
return _.isArray(cookies) ? _.map(cookies, rewriteCookie) : rewriteCookie(cookies)
})
for (const cookie of res.headers['set-cookie'] ?? []) {}

ctx.res.status(axiosRes.status).header(axiosRes.headers)
if (NODE_ENV !== 'production') {
exports.log({
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"dependencies": {
"@google-cloud/functions-framework": "^3.0.0",
"axios": "^0.26.1",
"dotenv": "^16.0.0",
"@google-cloud/functions-framework": "^3.4.2",
"axios": "^1.7.7",
"dotenv": "^16.4.5",
"http-errors": "^2.0.0",
"lodash": "^4.17.21"
},
Expand Down
Loading

0 comments on commit 6efece8

Please sign in to comment.