Skip to content

Commit ddcacee

Browse files
committed
fix(backend): serve static files only in production
1 parent 96edf6a commit ddcacee

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/service/index.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,16 @@ const createApp = async () => {
6464
app.use(express.json());
6565
app.use(express.urlencoded({ extended: true }));
6666
app.use('/', routes);
67-
app.use('/', express.static(absBuildPath));
68-
app.get('/*', (req, res) => {
69-
res.sendFile(path.join(`${absBuildPath}/index.html`));
70-
});
67+
68+
// In production, serves the static files from the build directory
69+
if (process.env.NODE_ENV === 'production') {
70+
app.use('/', express.static(absBuildPath));
71+
app.get('/*', (req, res) => {
72+
res.sendFile(path.join(`${absBuildPath}/index.html`));
73+
});
74+
} else {
75+
console.log('Not serving static files');
76+
}
7177

7278
return app;
7379
};

0 commit comments

Comments
 (0)