【问题标题】:Not able to lift sails in production mode.(sails lift --prod --verbose not working)无法在生产模式下升起帆。(sails lift --prod --verbose 不工作)
【发布时间】:2016-03-07 01:47:01
【问题描述】:

我想在生产模式下提升我的风帆。当我运行风帆提升 --prod --verbose 时,我遇到了一堆错误。 我的 local.js 文件看起来像这样。

  /**
     * Local environment settings
*
 * While you're developing your app, this config file should include
 * any settings specifically for your development computer (db   passwords, etc.)
 * When you're ready to deploy your app in production, you can use   this file
 * for configuration options on the server where it will be deployed.
 *
 *
 * PLEASE NOTE:
 *        This file is included in your .gitignore, so if you're using  git
 *        as a version control solution for your Sails app, keep in   mind that
 *        this file won't be committed to your repository!
 *
 *        Good news is, that means you can specify configuration for your local
 *        machine in this file without inadvertently committing personal information
 *        (like database passwords) to the repo.  Plus, this prevents other members
 *        of your team from commiting their local configuration changes on top of yours.
 *
 *
 * For more information, check out:
 * http://sailsjs.org/#documentation
 */
var config={

development:{
    connections: {

            mongo: {
            adapter: 'sails-mongo',
            host: 'localhost',
            user: '',
            password: '',
            database: 'mydata',
            schema: true
        }
    },
    mailer:{
        hostUrl:'http://localhost:1337/',
        emailConfirm:'confirm/',
        inviteMoreFriends:'myspace'
    },
    geoSpatial:{
        radiusOfEarth:6375,
        radius:3,
        maxRecords:20
    },
    facebook:{
        clientID: "CLIENT ID",
        clientSecret: "SECRET",
        callbackURL: "http://www.EXAMPLE.com:1337/auth/facebook/callback"
    }
}
}
module.exports = {


// The `port` setting determines which TCP port your app will be deployed on
// Ports are a transport-layer concept designed to allow many different
// networking applications run at the same time on a single computer.
// More about ports: http://en.wikipedia.org/wiki/Port_(computer_networking)
//
// By default, if it's set, Sails uses the `PORT` environment variable.
// Otherwise it falls back to port 1337.
//
// In production, you'll probably want to change this setting
// to 80 (http://) or 443 (https://) if you have an SSL certificate

port: process.env.PORT || 1337,


// The runtime "environment" of your Sails app is either 'development' or 'production'.
//
// In development, your Sails app will go out of its way to help you
// (for instance you will receive more descriptive error and debugging output)
//
// In production, Sails configures itself (and its dependencies) to optimize performance.
// You should always put your app in production mode before you deploy it to a server-
// This helps ensure that your Sails app remains stable, performant, and scalable.
//
// By default, Sails sets its environment using the `NODE_ENV` environment variable.
// If NODE_ENV is not set, Sails will run in the 'development' environment.

environment: process.env.NODE_ENV || 'development',


development: {
    //config is placed as the attributes needed by aws config node module
    aws: {
        region: 'REGION',
        accessKeyId: 'KEY ID',
        secretAccessKey: 'SECRET',
        cloudFrontCDN: 'EXAMPLE.cloudfront.net'
    },
    s3: {
        Bucket: 'MY_BUCKET',
        endpoint: 'ENDPOINT',
        imageUrl: 'URL'
    },
    uploads: {
        thumbnails: __dirname + '/../uploads/thumbnails/'
    }



},
likeprod: {
    //config is placed as the attributes needed by aws config node module
    aws: {
        region: 'REGION',
        accessKeyId: 'KEY ID',
        secretAccessKey: 'SECRET',
        cloudFrontCDN: 'EXAMPLE.cloudfront.net'
    },
    s3: {
        Bucket: 'MY_BUCKET',
        endpoint: 'ENDPOINT',
        imageUrl: 'URL'
    },
    uploads: {
        thumbnails: __dirname + '/../uploads/thumbnails/'
    }


},

mandrillApiKey:"API_KEY",
twilio:{
    accountSid:'SECRET',
    authToken:'TOKEN'
},
metaPublic:{
    groupBookNumber:'+0123456789'
},

    connections:config[process.env.NODE_ENV].connections,
    mailer:config[process.env.NODE_ENV].mailer,
    geoSpatial:config[process.env.NODE_ENV].geoSpatial,
    facebook:config[process.env.NODE_ENV].facebook,

//TODO: refactor the config[environment] as for connections
current: function () {
    return sails.config[sails.config.environment]
}

};

当我运行风帆升降机时--prod。我收到此错误。

 $ sails lift --prod --verbose

info: Starting app...

verbose: Please run `npm install coffee-script` to use coffescript     (skipping for now)
verbose: Setting Node environment...
verbose: moduleloader hook loaded successfully.
verbose: Loading app config...

/home/vgulp/Desktop/config/local.js:136
connections:config[process.env.NODE_ENV].connections,
                                        ^
TypeError: Cannot read property 'connections' of undefined
at Object.<anonymous> (/home/Desktop/vka/config/local.js:136:45)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at       /home/Desktop/vka/node_modules/sails/node_modules/include-all/index.js:129:29
at Array.forEach (native)
at requireAll (/home/Desktop/vka/node_modules/sails/node_modules/include-all/index.js:44:9)
at buildDictionary (/home/Desktop/vka/node_modules/sails/node_modules/sails-build-dictionary/index.js:68:14)
at Function.module.exports.aggregate (/home/Desktop/vka/node_modules/sails/node_modules/sails-build-dictionary/index.js:190:9)
at Array.loadOtherConfigFiles [as 0] (/home/Desktop/vka/node_modules/sails/lib/hooks/moduleloader/index.js:102:22)
at /home/Desktop/vka/node_modules/sails/node_modules/async/lib/async.js:459:38
at Array.forEach (native)
at _each (/home/Desktop/vka/node_modules/sails/node_modules/async/lib/async.js:32:24)
at Object.async.auto (/home/Desktop/vka/node_modules/sails/node_modules/async/lib/async.js:430:9)

谁能提出解决方案。

【问题讨论】:

  • 此应用程序是否部署到 Amazon EC2 上的实例?您是否检查了您的security groups 以确保端口 1337 已开放访问?
  • 是的,它部署在 Amazon EC2 上,并且端口 1337 已开放流量。
  • 在提供答案后,我对您完全改变了您的问题投了反对票。如果您有新/不同的问题,请提出新问题并添加评论链接到新问题,以便人们在需要时关注

标签: javascript node.js sails.js


【解决方案1】:

[已编辑:以下答案基于作者完全更改的原始问题]

您的sails 应用需要在生产模式下启动,或者您需要在配置文件中指定要使用的端口。

生产模式在端口 80 上运行您的 express 服务器。

您的 AWS 实例是否设置为在生产模式下提升应用程序?

http://sailsjs.org/documentation/anatomy/my-app/config/env/production-js

【讨论】:

  • 是的,我可以在生产模式下提升风帆应用程序,我可以通过输入 xx.xx.xxx.xx:1337 来访问它。如何在不指定端口的情况下使用 AWS 公共 IP 访问应用程序。
  • 您必须在端口 80(默认非 SSL Web 客户端端口)上解除。这是在生产中提升时默认使用的端口。
【解决方案2】:

您没有为local.js 中的production 指定连接(当您从桌面运行时)

正如错误所说,

connections:config[process.env.NODE_ENV].connections, ^ TypeError:无法读取未定义的属性“连接”

process.env.NODE_ENV--prod 中运行时为production

var config = {

    development: {
        connections: {

            mongo: {
                adapter: 'sails-mongo',
                host: 'localhost',
                user: '',
                password: '',
                database: 'mydata',
                schema: true
            }
        },
        mailer: {
            hostUrl: 'http://localhost:1337/',
            emailConfirm: 'confirm/',
            inviteMoreFriends: 'myspace'
        },
        geoSpatial: {
            radiusOfEarth: 6375,
            radius: 3,
            maxRecords: 20
        },
        facebook: {
            clientID: "CLIENT ID",
            clientSecret: "SECRET",
            callbackURL: "http://www.EXAMPLE.com:1337/auth/facebook/callback"
        }
    },
    production: {
        connections: {

            mongo: {
                adapter: 'sails-mongo',
                host: 'localhost',
                user: '',
                password: '',
                database: 'mydata',
                schema: true
            }
        },
        mailer: {
            hostUrl: 'http://localhost:1337/',
            emailConfirm: 'confirm/',
            inviteMoreFriends: 'myspace'
        },
        geoSpatial: {
            radiusOfEarth: 6375,
            radius: 3,
            maxRecords: 20
        },
        facebook: {
            clientID: "CLIENT ID",
            clientSecret: "SECRET",
            callbackURL: "http://www.EXAMPLE.com:1337/auth/facebook/callback"
        }
    }
}

【讨论】:

  • 它有效,但我在 bootstrap.js 中遇到了一个新错误。
  • /bootstrap.js:165 mkdirp(sails.config.current().uploads.thumbnails,function(err){ ^ TypeError: Cannot read property 'uploads' of undefined at createUploadDirectories (/home/ vgulp/Desktop/funvgulp/config/bootstrap.js:165:38)
  • @VaibhavKumarAmbeshta 用bootstrap.js 的内容更新问题或开始一个新问题。
  • @VaibhavKumarAmbeshta 将likeprod 中的local.js 更改为production
  • 是的,我已经改变了它。 Sails lift --prod 工作正常。
猜你喜欢
  • 1970-01-01
  • 2023-03-10
  • 2015-11-04
  • 1970-01-01
  • 1970-01-01
  • 2020-09-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多