【发布时间】:2020-09-10 14:24:29
【问题描述】:
我有几个 Node 应用程序在 Azure AppServices 上托管的 Docker 容器中运行。
我试图弄清楚如何处理 SameSite cookie 问题,但要做到这一点,我需要 https。目前,Node/Express 应用程序在容器内运行 http,然后 Azure 将我们的证书附加到 AppService 以运行 https。
我们正在使用带有以下选项的 cookie-session:
app.use(
cookieSession(
{
name: 'session',
keys: [ '123456789ABCD' ],
// Cookie Options
maxAge: 24 * 60 * 60 * 1000, // 24 hours
httpOnly: true,
sameSite: 'none',
secure: true
}
)
)
sameSite: 'none' 和 secure: true 是新的,但每当我部署 secure: true 时都会炸毁我的应用程序,因为我没有在容器内运行 http,所以 cookie 会被剥离。
我也试过app.set('trust proxy', 1),但不知道有什么影响。
Dockerfile:
# Create a container image for the app
FROM node:erbium-alpine
# Allow NODE_ENV to be set to different values
# depending on the image build/deployment environment
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
# Create app directory
WORKDIR /usr/app
# Copy package.json and yarn.lock into app directory
COPY ./package.json ./
COPY ./yarn.lock ./
# Install backend NPM modules
RUN yarn install
# COPY the client package and yarn files into app
COPY ./client/package.json ./client/
COPY ./client/yarn.lock ./client/
# Install client NPM modules
RUN yarn run install:client
# COPY the rest of the files into app directory
COPY ./ ./
# build the client
RUN yarn run build:client
# Expose ports for accessing the app
EXPOSE 5000 80
# Launch the Express server
CMD ["node", "server.js"]
考虑到这种部署方案,有什么好的方法?我是在容器中添加一些自签名证书,还是只是在某处缺少设置?
然后在我为 Azure 修复此问题后,如何在开发中运行它?
【问题讨论】:
标签: node.js azure docker https samesite