From b2c3fd2e81c786e0c65b6a1757784ef6aff872e5 Mon Sep 17 00:00:00 2001 From: Mizanali Panjwani Date: Tue, 2 Mar 2021 15:07:36 +0530 Subject: [PATCH] Deployment setup --- package.json | 3 ++- server.js | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 16aeb7e..024f8ac 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "main": "server.js", "scripts": { "start": "node server", - "client": "npm start --prefix client" + "client": "npm start --prefix client", + "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client" }, "repository": { "type": "git", diff --git a/server.js b/server.js index 0d71d1c..2232713 100644 --- a/server.js +++ b/server.js @@ -3,6 +3,7 @@ const socketio = require('socket.io') const http = require('http') const cors = require('cors') const { addUser, removeUser, getUser, getUsersInRoom } = require('./users') +const path = require('path') const PORT = process.env.PORT || 5000 @@ -51,6 +52,15 @@ io.on('connection', socket => { }) }) +//serve static assets in production +if(process.env.NODE_ENV === 'production') { + //set static folder + app.use(express.static('client/build')) + app.get('*', (req, res) => { + res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html')) + }) +} + server.listen(PORT, () => { console.log(`Server running on port ${PORT}`) }) \ No newline at end of file