最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

reactjs - Vite React Proxy Requests to Backend in Production - Stack Overflow

programmeradmin4浏览0评论

As I implement passport's Google OAuth2.0 strategy, I realized I need the callback to hit the server, then from there, I can redirect to a different page depending on if the user needs to finish setting up their account or if their account is already setup.

The problem is that when a redirect to say /api/auth/google/callback, the react app seems to capture it and just loads a blank screen. Even when my backend server is off which hosts the frontend, I still managed to get a blank page (I'm guessing just because everything is cached).

I believe I have everything in the correct order: handle API requests first, then send off the static react app files.

// Initialize Passport
app.use(passport.initialize());
app.use(passport.session());

passport.use(localStrategy);
passport.use(googleStrategy);

app.use('/api', apiRouter);

// serve react app 
app.use(express.static(path.join(__dirname, '../../frontend/dist')));

app.get('*', (req: Request, res: Response) => {
  res.sendFile(path.join(__dirname, '../../frontend/dist/index.html'));
});

I tried configuring a proxy in the vite config file, but that only seems to work in development. Any thoughts? Is this even possible?

发布评论

评论列表(0)

  1. 暂无评论