我已按照本教程进行操作,效果很好,但是当我尝试 dockerize 时,构建正常,但是当我运行映像时出现错误:错误:找不到模块'express'
DockerFile
FROM node:12 as buildContainer
WORKDIR /app
COPY ./package.json ./package-lock.json /app/
RUN npm install
COPY . /app
# max-old-space is needed to avoid any compilation issues because of missing memory
ENV NODE_OPTIONS --max-old-space-size=2048
RUN npm run build:ssr
FROM node:12-alpine
WORKDIR /app
COPY --from=buildContainer /app/package.json /app
# Get all the code needed to run the app
COPY --from=buildContainer /app/dist /app/dist
EXPOSE 4000
ENV NODE_ENV production
CMD ["npm", "run", "serve:ssr"]
我的 dist 结构是:
分布\应用
- 浏览器 -- en -- fr
- 服务器 -- en -- fr proxy-server.js
代理服务器.js
const express = require("express");
const path = require("path");
const getTranslatedServer = (lang) => {
const distFolder = path.join(
process.cwd(),
`dist/morefont-v4/server/${lang}`
);
const server = require(`${distFolder}/main.js`);
return server.app(lang);
};
function run() {
const port = 4000;
// Start up the Node server
const appFr = getTranslatedServer("fr");
const appEn = getTranslatedServer("en");
const server = express();
server.use("/fr", appFr);
server.use("/en", appEn);
server.use("", appEn);
server.listen(port, () => {
console.log(`Node Express server listening on http://localhost:${port}`);
});
}
run();
可选问题:您是否有正确的方法将 I18n 与 Angular SSR 一起使用?
问题:如何修复我的 Docker 映像以导入 node_modules?
谢谢