diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..aeaeb87b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM node:16.13 +WORKDIR /usr/src/app +COPY . /usr/src/app +RUN npm install +RUN npm run build +EXPOSE 3000 +ENTRYPOINT ["node", "./server/server.js"] diff --git a/index.html b/index.html index bda8488c..2af4a2df 100644 --- a/index.html +++ b/index.html @@ -9,7 +9,7 @@
- + diff --git a/server/server.js b/server/server.js index 0f48eaca..7376ac0e 100644 --- a/server/server.js +++ b/server/server.js @@ -3,6 +3,8 @@ const express = require('express'); const session = require("express-session"); const passport = require('passport'); +const path = require('path'); + require('dotenv').config(); require('./auth'); @@ -83,6 +85,15 @@ app.get('/logout', ( req,res)=> { // Implementation is flexibile, can change if needed app.use('/api', apiRouter); +// statically serve everything in the build folder on the route '/build' +if (process.env.NODE_ENV === 'production') { + app.use('/dist', express.static(path.join(__dirname, '../dist'))); + // serve index.html on the route '/' + app.get('/', (req, res) => { + return res.status(200).sendFile(path.join(__dirname, '../index.html')); + }); +} + // Catch-all error handler app.use('*', (req, res) => { res.sendStatus(404); diff --git a/webpack.config.js b/webpack.config.js index f1c436d4..c6e6fc2b 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -4,11 +4,12 @@ const HtmlWebpackPlugin = require('html-webpack-plugin'); module.exports = { entry: './client/index.tsx', output: { - path: path.join(__dirname, 'dist'), filename: 'bundle.js', + path: path.join(__dirname, 'dist'), + clean: true, publicPath: '/', }, - devtool: 'eval-source-map', //comment it out when doing the production run + // devtool: 'eval-source-map', //comment it out when doing the production run devServer: { host: 'localhost', port: 8080, @@ -28,15 +29,15 @@ module.exports = { }, '/protected': { target: 'http://localhost:3000', - secure: false + secure: false, }, '/logout': { target: 'http://localhost:3000', - secure: false + secure: false, }, '/google/**': { target: 'http://localhost:3000', - secure: false + secure: false, }, }, static: {