我刚开始使用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);
}