1
0
mirror of https://github.com/mizanxali/uno-online synced 2024-11-21 18:24:53 +00:00

Deployment setup

This commit is contained in:
Mizanali Panjwani 2021-03-02 15:07:36 +05:30
parent 622a695a40
commit b2c3fd2e81
2 changed files with 12 additions and 1 deletions

View File

@ -5,7 +5,8 @@
"main": "server.js", "main": "server.js",
"scripts": { "scripts": {
"start": "node server", "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": { "repository": {
"type": "git", "type": "git",

View File

@ -3,6 +3,7 @@ const socketio = require('socket.io')
const http = require('http') const http = require('http')
const cors = require('cors') const cors = require('cors')
const { addUser, removeUser, getUser, getUsersInRoom } = require('./users') const { addUser, removeUser, getUser, getUsersInRoom } = require('./users')
const path = require('path')
const PORT = process.env.PORT || 5000 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, () => { server.listen(PORT, () => {
console.log(`Server running on port ${PORT}`) console.log(`Server running on port ${PORT}`)
}) })