小编lud*_*ico的帖子

跨域会话 Cookie(Heroku 上的 Express API + Netlify 上的 React App)

我有一个 React 应用程序调用 node.js/Express 中的 API。

前端部署在 Netlify (https),​​后端部署在 Heroku (https)。

我的问题:

  • 在开发环境(本地主机)中工作的一切
  • 在生产(Netlify/Heroku)中,用于注册和登录的 api 调用似乎有效,但会话 cookie 未存储在浏览器中。因此,对 API 中受保护路由的任何其他调用都会失败(因为我没有收到用户凭据)。

             跨域身份验证 cookie react express




说话很便宜,给我看代码....

后端(Express API):

应用程序.js

require('./configs/passport');

// ...

const app = express();

// trust proxy (https://stackoverflow.com/questions/64958647/express-not-sending-cross-domain-cookies)
app.set("trust proxy", 1); 

app.use(
  session({
    secret: process.env.SESSION_SECRET,
    cookie: {
      sameSite: process.env.NODE_ENV === "production" ? 'none' : 'lax',
      maxAge: 60000000,
      secure: process.env.NODE_ENV === "production",
    },
    resave: true,
    saveUninitialized: false,
    ttl: 60 * 60 * 24 * 30 …
Run Code Online (Sandbox Code Playgroud)

heroku session-cookies express reactjs express-session

10
推荐指数
1
解决办法
6558
查看次数

如何在JavaScript中将常数加到innerWidth?

我试图在JS中对innerWidthand 进行求和constant numbers,但是浏览器一直仅附加这些数字,而不进行计算。

在此处输入图片说明

奇怪的是给负值工作正常。仅当我尝试将数字加到时,浏览器才会计算innerWidth

有什么办法可以解决这个问题?

  Slider.prototype.sizeReseting = function(event) {
    this.frame.style.height = (window.innerWidth - '300') + 'px';
    this.frame.style.width = (window.innerWidth - '300') + 'px';
    this.film.style.height = (window.innerWidth - '400') + 'px';
    this.film.style.width = (window.innerWidth + '100') + 'px';
  }
Run Code Online (Sandbox Code Playgroud)

javascript css string-concatenation

2
推荐指数
1
解决办法
65
查看次数