[英]Making referrer and querystring available to a frame under a different domain
[英]Making a cookie available to a sibling domain with Ember
在 Ember 应用程序中,我们使用ember-cookie
设置 cookies 。 目前, userToken
cookie 仅对www.example.com
可用。 我需要将它提供给api.example.com
并且期望下面的代码可以工作:即使domain
(实际上是通过环境变量设置)以“www”开头,cookie 也应该设置更高一级(并且因此也可用于api
子域)。
set cookieToken(token) {
let domain = 'www.example.com';
// Share with main domain (and API subdomain) even if host is www subdomain
if (domain.startsWith('www')) {
const apiSubdomain = domain.replace(/^www/, '');
this.cookies.write('userToken', JSON.stringify(token), { path: '/', apiSubdomain })
}
}
然而,这种方法失败了:
我还尝试为api.example.com
明确设置 cookie:
if (domain.startsWith('www')) {
const apiSubdomain = domain.replace(/^www/, 'api');
this.cookies.write('userToken', JSON.stringify(token), { path: '/', apiSubdomain })
}
结果是一样的:
我该怎么做才能使两个子域都可以访问此 cookie?
问题是我没有在选项 hash 中指定domain
密钥。 以下代码会起作用,因为domain
等效于domain: domain
:
this.cookies.write('userToken', JSON.stringify(token), { path: '/', domain })
然而,在我的例子中,我以不同的方式命名了变量,所以我需要明确指定键:
this.cookies.write('userToken', JSON.stringify(token), { path: '/', domain: apiSubdomain })
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.