0

我刚开始使用NodeJS ,想使用像Express 中间件一样部署的(使用这个文档 - http://docs.deployd.com/docs/server/work-with-express.html)。

但我不明白路由器的工作原理(现在对我来说太深了)。所以,我无法到达仪表板。

所以,这里有个无礼的问题——当我使用像中间件一样部署的时候,我如何才能到达仪表板?我的应用程序只是由 express-generator 生成的,如下所示:

/**
 * Module dependencies.
 */

var app = require('../app');
var debug = require('debug')('truckDeploy:server');
var http = require('http');
var ENV = process.env.NODE_ENV || 'development';

/**
 * Get port from environment and store in Express.
 */

var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);

/**
 * Create HTTP server.
 */

var server = http.createServer(app);

var io = require('socket.io').listen(server, {'log level': 0});

// setup deployd
require('deployd').attach(server, {
  socketIo: io,  // if not provided, attach will create one for you.
  env: ENV,
  db: {host:'localhost', port:27017, name:'truck-db'}
});

/**
 * Listen on provided port, on all network interfaces.
 */

app.use(server.handleRequest);
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);

/**
 * Normalize a port into a number, string, or false.
 */

function normalizePort(val) {
  var port = parseInt(val, 10);

  if (isNaN(port)) {
    // named pipe
    return val;
  }

  if (port >= 0) {
    // port number
    return port;
  }

  return false;
}

/**
 * Event listener for HTTP server "error" event.
 */

function onError(error) {
  if (error.syscall !== 'listen') {
    throw error;
  }

  var bind = typeof port === 'string'
    ? 'Pipe ' + port
    : 'Port ' + port;

  // handle specific listen errors with friendly messages
  switch (error.code) {
    case 'EACCES':
      console.error(bind + ' requires elevated privileges');
      process.exit(1);
      break;
    case 'EADDRINUSE':
      console.error(bind + ' is already in use');
      process.exit(1);
      break;
    default:
      throw error;
  }
}

/**
 * Event listener for HTTP server "listening" event.
 */

function onListening() {
  var addr = server.address();
  var bind = typeof addr === 'string'
    ? 'pipe ' + addr
    : 'port ' + addr.port;
  debug('Listening on ' + bind);
}
4

1 回答 1

1

根据运行代码后您需要访问的文档: http://localhost:3000/dashboard/ 。

为了在没有密钥的情况下访问 /dashboard,您必须运行 Deployd 并将 env 选项设置为 development。

这是假设

var app = require('../app');

相当于实例化一个 express 应用,所以:

var app = require('express')();
于 2015-06-30T03:26:14.943 回答