启动节点Webkit之前如何启动Meteor实例? [英] How can I start a Meteor instance before launching a node-webkit?
问题描述
我已经开发了一个 Meteor 应用.我想将此应用程序打包在Chromium的node-webkit应用程序运行时中.我需要Meteor服务器进程在本地运行. 当用户启动node-webkit应用程序时,我将如何启动Meteor服务器进程?
I have developed a Meteor app. I would like to package this app in the node-webkit app runtime for Chromium. I need the Meteor server process to run locally. How would I go about starting the Meteor server process when a user launches the node-webkit app?
我知道我可以像这样用node-webkit启动NodeJS服务器实例:
I know I can start a NodeJS server instance with node-webkit like this:
#!/usr/bin/env node
require('http').createServer(function(req, res) {
res.writeHead(200, {'content-type': 'text/html'});
res.end('<h1>sup</h1>');
}).listen(9000, '127.0.0.1');
然后如果我跑步:
$ nw ./
node-webkit将启动NodeJS服务器并启动node-webkit实例.我没有在此处包括package.json文件,但实际上它只是说看http://127.0.0.1:9000
.
node-webkit will start the NodeJS server and launch the node-webkit instance. I'm not including the package.json file here, but it essentially just says look at http://127.0.0.1:9000
.
那么,如何在node-wekkit应用程序运行时编写server.js
文件以启动Meteor实例?
So, how would I go about writing that server.js
file to start the Meteor instance while the node-wekkit app is running?
感谢您的任何想法.
推荐答案
首先将流星应用程序meteor build --directory /your/node-webkit/project/
捆绑在一起,并使用此代码启动您的应用程序.但是,将Meteor与node-webkit打包可能会稍微复杂一些.首先,您需要在客户端计算机上或客户端可以随时连接的位置上运行mongodb服务器.
First Bundle your meteor app meteor build --directory /your/node-webkit/project/
and use this code to start your app. But, packaging Meteor with node-webkit can be a little bit more complicated. First, you'll need a mongodb server running on your client computer or somewhere the client can connect anytime.
var path = require('path');
var child_process = require('child_process');
// change these
var PORT = 9000;
var ROOT_URL = 'http://localhost:'+PORT;
var MONGO_URL = 'mongodb://localhost:27017/my_app_db';
var NODE_BIN = '/usr/local/bin/node';
// install npm dependencies
var options = {cwd: path.resolve(__dirname, 'bundle/programs/server/')};
var installNpm = child_process.exec('npm install', options, onNpmInstall);
function onNpmInstall (err, stderr, stdout) {
if(err) throw new Error('could not install npm dependencies');
// start Meteor
var options = {
env: {PORT: PORT, MONGO_URL: MONGO_URL, ROOT_URL: ROOT_URL},
cwd: __dirname
};
var proc = child_process.spawn(NODE_BIN, ['bundle/main.js'], options);
proc.on('close', function (code) {
console.log('Meteor exited with code ' + code);
});
}
如果要使用100%的客户端应用程序,则必须删除与mongo相关的智能软件包.
You must remove mongo related smart packages if you want a 100% client-side application.
这篇关于启动节点Webkit之前如何启动Meteor实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!