docker容器中sailsjs应用程序中的ReferenceError

时间:2019-06-28 10:48:26

标签: docker docker-compose sails.js dockerfile sails-mongo

我正在使用Sails应用程序在我的应用程序中,我使用了 mysql mongo adpater连接不同的数据库。两个数据库都托管在Internet上的某个位置。应用程序在我的本地环境中运行良好。将项目添加到Docker容器后,我面临问题。我能够生成docker映像并运行docker容器。当我调用不存在数据库连接的简单路由器时,它工作正常,但是当我调用 Testcontroller 时,该路由器从mongodb返回数据。它给了我ReferenceError: Test is not define.,这里Test是mongodb的实体。

DockerFile:

FROM node:latest
ENV NODE_ENV production
WORKDIR /usr/src/app
COPY ["package.json", "./"]
RUN npm install --verbose --force && mv node_modules ../
COPY . .
EXPOSE 80
CMD npm start

TestController

/**
 * TestController
 * @description :: Server-side actions for handling incoming requests.
 *
 * @help        :: See https://sailsjs.com/docs/concepts/actions
 */

module.exports = {
  index: async function(req, res) {
    var data = await Test.find(); // Here I am getting error Test is not define.
    res.json(data);
  }
};

Routes.js

'GET /test': {controller:'test', action:'index'}

1 个答案:

答案 0 :(得分:0)

我发现了问题,我正在将 node_modules 移到问题所在的先前目录中。

以下配置对我有用。

FROM node:latest
ENV NODE_ENV production
WORKDIR /usr/src/app
COPY ["package.json", "./"]
RUN npm install --verbose --force
COPY . .
EXPOSE 80
CMD npm start