eggjs 跨域配置

M1n90發表於2024-08-07

1. config.default.js

config.session = {
 ...
sameSite: "none",
secure: true,
};
config.cors = {
origin: "xxx",
credentials: true,
allowMethods: "GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS",
};
config.security = {
csrf: {
enable: false,
},
domainWhiteList: ["*"],
};
// 若報錯:Cannot send secure cookie over unencrypted connection,加上
config.proxy = true;
// nginx 配置
server {
  server_name xxx.com;
  proxy_set_header X-Forwarded-Proto $scheme;
}

相關文章