Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support function to set domain #38

Merged
merged 2 commits into from
Aug 4, 2023

Conversation

onlylovermb
Copy link
Member

@onlylovermb onlylovermb commented Aug 4, 2023

Checklist
  • npm test passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)
Description of change

由于 set-cookies 时无法设置多 domain
image
支持 domain 传入函数,当有多个不同域名访问时,可由用户自定义动态设置 domain,示例如下

// config.default.js
exports.session = {
    domain:  () => '.abc.com'
};

@codecov
Copy link

codecov bot commented Aug 4, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (d98e1c1) 100.00% compared to head (f057f3f) 100.00%.

❗ Current head f057f3f differs from pull request most recent head e7b0a6a. Consider uploading reports for the commit e7b0a6a to get more accurate results

Additional details and impacted files
@@            Coverage Diff            @@
##            master       #38   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            4         4           
  Lines          203       207    +4     
  Branches        51        52    +1     
=========================================
+ Hits           203       207    +4     
Files Changed Coverage Δ
lib/cookie.js 100.00% <100.00%> (ø)
lib/cookies.js 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

lib/cookie.js Outdated Show resolved Hide resolved
Copy link
Member

@fengmk2 fengmk2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@fengmk2 fengmk2 merged commit c73b415 into eggjs:master Aug 4, 2023
6 checks passed
fengmk2 pushed a commit that referenced this pull request Aug 4, 2023
[skip ci]

## [2.7.0](v2.6.1...v2.7.0) (2023-08-04)

### Features

* support function to set domain ([#38](#38)) ([c73b415](c73b415))
@github-actions
Copy link

github-actions bot commented Aug 4, 2023

🎉 This PR is included in version 2.7.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@@ -28,7 +28,11 @@ class Cookie {
this.value = value || '';
this.attrs = mergeDefaultAttrs(attrs);
assert(!this.attrs.path || fieldContentRegExp.test(this.attrs.path), 'argument option path is invalid');
assert(!this.attrs.domain || fieldContentRegExp.test(this.attrs.domain), 'argument option domain is invalid');
assert(!this.attrs.domain || typeof this.attrs.domain === 'string' || typeof this.attrs.domain === 'function', 'argument option domain is invalid');
Copy link
Member

@fengmk2 fengmk2 Aug 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nodejs.AssertionError: argument option domain is invalid
    at new Cookie (/home/admin/app/node_modules/_egg-cookies@2.7.0@egg-cookies/lib/cookie.js:35:5)
    at Cookies.set (/home/admin/app/node_modules/_egg-cookies@2.7.0@egg-cookies/lib/cookies.js:124:20)
    at updateCookie (/home/admin/app/node_modules/_koa-locales@1.12.0@koa-locales/index.js:254:17)
    at Object.app.context.__getLocale (/home/admin/app/node_modules/_koa-locales@1.12.0@koa-locales/index.js:224:7)
    at Object.get locale [as locale] (/home/admin/app/node_modules/_egg-i18n@2.1.1@egg-i18n/app/extend/context.js:10:17)

fengmk2 added a commit that referenced this pull request Aug 4, 2023
@fengmk2 fengmk2 mentioned this pull request Aug 4, 2023
4 tasks
fengmk2 added a commit that referenced this pull request Aug 4, 2023
fengmk2 pushed a commit that referenced this pull request Aug 4, 2023
[skip ci]

## [2.7.1](v2.7.0...v2.7.1) (2023-08-04)

### Bug Fixes

* domain can be empty string ([#39](#39)) ([0b285e1](0b285e1)), closes [/github.com//pull/38#discussion_r1284672929](https://github.com/eggjs//github.com/eggjs/egg-cookies/pull/38/issues/discussion_r1284672929)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants