Skip to content

Commit 7960a4c

Browse files
committed
Serve static files in build directory
1 parent 8fcbffd commit 7960a4c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,16 @@ app.use(bodyParser.urlencoded({ extended: true }));
99

1010
app.use('/api/todos', todoRoutes);
1111

12+
if (process.env.NODE_ENV === 'production') {
13+
// Express will serve up production assets
14+
// like our main.js file, or main.css file!
15+
app.use(express.static('client/build'));
16+
17+
// Express will serve up the index.html file
18+
// if it doesn't recognize the route
19+
const path = require('path');
20+
app.get('*', (req, res) =>
21+
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
22+
);
23+
}
1224
app.listen(port, () => console.log(`Server starts on ${port}...`));

0 commit comments

Comments
 (0)