我拼命地尝试让会话cookie在我的环境中工作,但到目前为止还没有运气。
我的后端是一个节点/express 应用程序,在端口 3000 上运行。CORS 启用如下:
const corsOptions = {
origin: "http://127.0.0.1:4300",
allowedHeaders: [ "Origin", "X-Requested-With", "Content-Type", "Accept", "Authorization", "x-xsrf-token" ],
credentials: true
};
if (isDebug) {
corsOptions.maxAge = 1;
}
app.use(cors(corsOptions));
Run Code Online (Sandbox Code Playgroud)
我使用快速会话和护照进行登录。会话配置如下:
const options = {
secret: '...',
cookie: { httpOnly: true }
};
app.use(session(options));
Run Code Online (Sandbox Code Playgroud)
前端是 Angular 2 SPA,在端口 4300 上运行。当我从 Express 服务器为前端提供服务时,一切都按预期工作。但如果没有,我会遇到以下晦涩的问题:
登录路由返回带有会话 ID 的 cookie。但是到后端的下一个请求是使用不同的会话 ID 发送的?!我不知道这个不同的会话 ID 是从哪里来的。特别是因为会话 cookie 被标记为仅限 HTTP。
HTTP 请求的发送方式如下:
const response = this.http.get(url, { withCredentials: true });
Run Code Online (Sandbox Code Playgroud)
我尝试了以下方法:
我正在尝试使用 yarn 工作区,然后将我的应用程序放入 Docker 映像中。
文件夹结构如下所示:
不幸的是,Docker 不支持符号链接 - 因此不可能将根目录中的 node_modules 文件夹复制到 Docker 映像中,即使 Dockerfile 像我一样位于根目录中。
我可以做的一件事是用 .dockerignore 排除符号链接,然后将真实目录复制到图像中。
另一个想法——我更喜欢——是有一个工具,用符号链接的实际内容替换符号链接。不知道有没有这样的工具(最好是Javascript包)?
谢谢
如何动态地将*ngIf添加到使用属性指令修饰的元素?
对于一个简单的实验,我试过这个:
@Directive({
selector: '[lhUserHasRights]'
})
export class UserHasRightsDirective implements OnInit, OnDestroy {
constructor(private el: ElementRef) {
}
ngOnInit(): void {
this.el.nativeElement.setAttribute("*ngIf", "false");
}
...
Run Code Online (Sandbox Code Playgroud)
,但它没有用.浏览器向我显示错误" 错误DOMException:无法在'Element'上执行'setAttribute':' ngIf'不是有效的属性名称. "