fix build docker container

This commit is contained in:
Chika 2020-11-14 22:12:51 +03:00
parent e8f920d373
commit e641b06e23
3 changed files with 18 additions and 10 deletions

View File

@ -2,4 +2,5 @@ node_modules
npm-debug.log
yarn.lock
yarn-error.log
*.log
*.log
.git

View File

@ -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

View File

@ -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}`);
});