如何在启动 node-webkit 之前启动 Meteor 实例? [英] How can I start a Meteor instance before launching a node-webkit?

查看:25
本文介绍了如何在启动 node-webkit 之前启动 Meteor 实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个 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.

那么,我将如何编写 server.js 文件以在 node-wekkit 应用程序运行时启动 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 app meteor build --directory/your/node-webkit/project/ 并使用此代码开始你的应用程序.但是,使用 node-webkit 打包 Meteor 可能会稍微复杂一些.首先,您需要在客户端计算机上或客户端可以随时连接的地方运行 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.

这篇关于如何在启动 node-webkit 之前启动 Meteor 实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆