Running Meteor Build under Node with settings argument

元气小坏坏 提交于 2019-12-12 12:21:52

问题


Typically when developing I would use meteor run --settings settings.json. This works fine and can view the settings in the browser with Meteor.settings on the console.

I am now build for production, using meteor build, I've looked at the documentation and there is nowhere to add settings during the build process.

So the build runs and I have my .tar.gz file, it's loaded to production and then I untar/compress the folder and run the start script.

It enters the program with npm start and the package.json section looks like this (ignore the stop script);

{
  "name": "myapp",
  "scripts": {
    "start": "node main.js --settings settings.json",
    "stop": "killall node"
  }
}

When I look at my app it is not collecting these settings. It is as if when bundled it doesn't expect the arguements. I also tried using forever beforehand, but I had no joy with this either.

Any help would appreciated, start to wish I never bothered with Meteor :)


回答1:


You can refer to Meteor Guide > Production > Deployment and Monitoring > Environment variables and Settings

Settings. These are in a JSON object set via either the --settings Meteor command-line flag or stringified into the METEOR_SETTINGS environment variable.

As for setting environment variables, if you use a 3rd party host, you may have a GUI or CLI to define them.

Otherwise, you should have plenty resources including on SO:

  • Node.js: Setting Environment Variables
  • How can I set an environmental variable in node.js?
  • https://themeteorchef.com/snippets/making-use-of-settings-json/

In short, it should look like:

METEOR_SETTINGS='{"key":"value"}' node main.js

You can also try the bash cat command to extract the content of a file: $(cat settings.json)



来源:https://stackoverflow.com/questions/38998908/running-meteor-build-under-node-with-settings-argument

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!