-
Notifications
You must be signed in to change notification settings - Fork 586
/
bin.js
31 lines (26 loc) · 953 Bytes
/
bin.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
29
30
31
#!/usr/bin/env node
'use strict';
var STATIC_OPTIONS = { maxAge: 3600000 };
var process = require('process');
process.title = 'peerflix-server';
var express = require('express'),
http = require('http'),
path = require('path'),
serveStatic = require('serve-static'),
socket = require('./socket'),
api = require('./')
.use(serveStatic(path.join(__dirname, '../dist'), STATIC_OPTIONS))
.use(serveStatic(path.join(__dirname, '../.tmp'), STATIC_OPTIONS))
.use(serveStatic(path.join(__dirname, '../app'), STATIC_OPTIONS));
var server = http.createServer(api);
socket(server);
var port = process.env.PORT || 9000;
server.listen(port).on('error', function (e) {
if (e.code !== 'EADDRINUSE' && e.code !== 'EACCES') {
throw e;
}
console.error('Port ' + port + ' is busy. Trying the next available port...');
server.listen(++port);
}).on('listening', function () {
console.log('Listening on http://localhost:' + port);
});