forked from jhurliman/node-echoprint-server
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
28 lines (24 loc) · 984 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
var http = require('http');
var urlParser = require('url');
var qs = require('querystring');
var log = require('winston');
var config = require('./config');
var server = require('./server');
// Make sure we have permission to bind to the requested port
if (config.web_port < 1024 && process.getuid() !== 0)
throw new Error('Binding to ports less than 1024 requires root privileges');
// Start listening for web requests
server.init();
// If run_as_user is set, try to switch users
if (config.run_as_user) {
try {
process.setuid(config.run_as_user);
log.info('Changed to running as user ' + config.run_as_user);
} catch (err) {
log.error('Failed to change to user ' + config.run_as_user + ': ' + err);
}
}
// Now that we've dropped root privileges (if requested), setup file logging
// NOTE: Any messages logged before this will go to the console only
if (config.log_path)
log.add(log.transports.File, { level: config.log_level, filename: config.log_path });