You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working on a project using React Router v7 in framework mode (formerly part of Remix), and I’m encountering a CORS error when making a POST request to an action endpoint in production.
Initially I did not have a custom node server but after trying to set the response headers to allow all origins to no avail I sought to try a custom express server which does not equally work
Setup Overview
React Router v7 (Framework mode)
Custom Express server
Vite for development
TypeScript
Dev tunnels (to simulate production environment)
Express Server Configuration
Here's a simplified version of my server.ts:
importexpressfrom"express";importcorsfrom"cors";importcompressionfrom"compression";importmorganfrom"morgan";constapp=express();app.use(cors({origin: "*",credentials: true}));app.use(compression());app.use(morgan("dev"));if(process.env.NODE_ENV==="development"){constvite=awaitimport("vite");constviteDevServer=awaitvite.createServer({server: {middlewareMode: true}});app.use(viteDevServer.middlewares);app.use(async(req,res,next)=>{try{constsource=awaitviteDevServer.ssrLoadModule("./server/app.ts");returnawaitsource.app(req,res,next);}catch(error){viteDevServer.ssrFixStacktrace?.(error);next(error);}});}else{app.use("/assets",express.static("build/client/assets",{immutable: true,maxAge: "1y"}));app.use(express.static("build/client",{maxAge: "1h"}));app.use(awaitimport("./build/server/index.js").then((mod)=>mod.app));}app.listen(process.env.PORT||5500,()=>{console.log("Server is running...");});
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone ,
I'm working on a project using React Router v7 in framework mode (formerly part of Remix), and I’m encountering a CORS error when making a
POST
request to an action endpoint in production.Initially I did not have a custom node server but after trying to set the response headers to allow all origins to no avail I sought to try a custom express server which does not equally work
Setup Overview
Express Server Configuration
Here's a simplified version of my
server.ts
:In my webhook endpoint
Beta Was this translation helpful? Give feedback.
All reactions