dockerfile
FROM harbor.newegg.org/base/node:12-alpine as build-stage
WORKDIR /app
COPY package*.json ./
RUN npm install --registry=https://a.newegg.org/artifactory/api/npm/newegg-npm/
RUN npm run build
COPY . .
# production stage
FROM harbor.newegg.org/base/node:12-alpine as production-stage
WORKDIR /app
RUN npm install express --registry=https://a.newegg.org/artifactory/api/npm/newegg-npm/ --save
COPY server.js ./
COPY --from=build-stage /app/dist ./dist/
EXPOSE 8080
CMD ["node", "server.js"]
根目录创建server.js
const express = require('express');
const path = require('path')
const app = express();
app.use(express.static(path.join(__dirname, 'dist')));
app.get('/*', function (req, res) {
res.sendFile(path.join(__dirname, 'dist', 'index.html'));
});
app.listen(8080, function () {
console.log('http://localhost:8080/index.html');
});
网友评论