Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env node
- /**
- * Module dependencies.
- */
- var app = require('../app');
- var debug = require('debug')('forumforum:httpServer');
- var http = require('http');
- /**
- * Get port_public from environment and store in Express.
- */
- var port_public = normalizePort(process.env.PORT || '80');
- app.set('port_public', port_public);
- /**
- * Create HTTP httpServer.
- */
- var httpServer = http.createServer(app);
- /**
- * Listen on provided port_public, on all network interfaces.
- */
- httpServer.listen(port_public);
- httpServer.on('error', onError);
- httpServer.on('listening', onListening);
- /**
- * Normalize a port_public into a number, string, or false.
- */
- function normalizePort(val) {
- var port_public = parseInt(val, 10);
- if (isNaN(port_public)) {
- // named pipe
- return val;
- }
- if (port_public >= 0) {
- // port_public number
- return port_public;
- }
- return false;
- }
- /**
- * Event listener for HTTP httpServer "error" event.
- */
- function onError(error) {
- if (error.syscall !== 'listen') {
- throw error;
- }
- var bind = typeof port_public === 'string'
- ? 'Pipe ' + port_public
- : 'Port ' + port_public;
- // 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 httpServer "listening" event.
- */
- function onListening() {
- var addr = httpServer.address();
- var bind = typeof addr === 'string'
- ? 'pipe ' + addr
- : 'port_public ' + addr.port_public;
- debug('Listening on ' + bind);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement