Skip to content

Commit edc0e6f

Browse files
committed
Always allow localhost CORS requests
1 parent 33db5fb commit edc0e6f

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

Diff for: server/server.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,16 @@ if (process.env.BASIC_USERNAME && process.env.BASIC_PASSWORD) {
4646
}));
4747
}
4848

49-
const corsOriginsWhitelist = [
49+
const allowedCorsOrigins = [
5050
/p5js\.org$/,
51+
/localhost/ // to allow client-only development
5152
];
5253

5354
// Run Webpack dev server in development mode
5455
if (process.env.NODE_ENV === 'development') {
5556
const compiler = webpack(config);
5657
app.use(webpackDevMiddleware(compiler, { noInfo: true, publicPath: config.output.publicPath }));
5758
app.use(webpackHotMiddleware(compiler));
58-
59-
corsOriginsWhitelist.push(/localhost/);
6059
}
6160

6261
const mongoConnectionString = process.env.MONGO_URL;
@@ -65,7 +64,7 @@ app.set('trust proxy', true);
6564
// Enable Cross-Origin Resource Sharing (CORS) for all origins
6665
const corsMiddleware = cors({
6766
credentials: true,
68-
origin: corsOriginsWhitelist,
67+
origin: allowedCorsOrigins,
6968
});
7069
app.use(corsMiddleware);
7170
// Enable pre-flight OPTIONS route for all end-points

0 commit comments

Comments
 (0)