diff --git a/.dockerignore b/.dockerignore index 6767ab8..b5337d4 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,4 +2,5 @@ node_modules npm-debug.log yarn.lock yarn-error.log -*.log \ No newline at end of file +*.log +.git \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 36f60d1..b74ccd5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,14 @@ FROM node:14-alpine +ENV NODE_ENV production + WORKDIR /home/app -COPY . . +COPY package.json ./ -RUN yarn +RUN npm install -RUN yarn build +COPY build ./ EXPOSE 3001 diff --git a/src/server/index.ts b/src/server/index.ts index 3a5798e..6f7b57d 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -13,7 +13,10 @@ import { SERVER_PORT } from './../core/constants/urls'; const isDevelopmentMode = process.env.NODE_ENV === 'development'; -const buildDir = path.join(process.cwd(), isDevelopmentMode ? '/build' : ''); +const buildDir = path.join( + process.cwd(), + process.env.NODE_ENV === 'development' ? '/build' : '', +); const app = express(); @@ -46,13 +49,15 @@ app.use('/', routes); /**ROUTES */ /**CLIENT */ -app.use(express.static(buildDir)); -app.get('*', function (req, res) { - res.sendFile(path.join(buildDir, 'index.html')); -}); +if (!isDevelopmentMode) { + app.use(express.static(buildDir)); + app.get('*', function (req, res) { + res.sendFile(path.join(buildDir, 'index.html')); + }); +} /**CLIENT */ -console.log('checking port', SERVER_PORT); +console.log(process.env.NODE_ENV); app.listen(SERVER_PORT, () => { console.log(`Server now listening on port: ${SERVER_PORT}`); });