-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.old.js
executable file
·104 lines (90 loc) · 3.01 KB
/
index.old.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
var express = require('express');
var execPath = process.env.PWD;
var fs = require('fs');
var cookieParser = require('cookie-parser');
var cookieSession = require('cookie-session');
var apiFactory = require('./api.js');
var app = express();
var appFinder = require('./appfinder')
var bodyParser = require('body-parser');
app.use(bodyParser());
//var busy = require('busy');
var server = require('http').createServer(app);
var favicon = require('serve-favicon')
var api = apiFactory(server);
var nodeadmin = require('nodeadmin');
app.use(nodeadmin(app));
app.maxConnections = 200;
process.on('unhandledRejection', (reason, p) => {
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
// application specific logging, throwing an error, or other logic here
});
app.timeout = 1000;
app.use(cookieParser());
app.use(cookieSession({
secret:'32425235235235',
name: 'session',
keys: ['key1', 'key2'],
cookie: {secure: false}
}));
var path = require('path');
/*
// middleware which blocks requests when we're too busy
app.use(function(req, res, next) {
if (busyCheck.blocked) {
res.send(503, "I'm busy right now, sorry.");
} else {
next();
}
});*/
app.use('/api', api.app);
/*
var busyCheck = busy(function(amount) {
console.log('Loop was busy for', amount, 'ms');
});*/
app.use(express.static(__dirname + '/client/'));
app.get('/callback.html', function (req, res) {
var index = fs.readFileSync(__dirname + '/client/callback.html');
res.write(index);
res.end();
});
app.get('/callback/:service', function (req, res) {
var index = fs.readFileSync(__dirname + '/client/callback.html');
res.write(index);
res.end();
});
app.use(favicon(path.join(__dirname, 'client', 'favicon.ico')))
app.get('/*', function (req, res) {
try { var protocol = req.connection.encrypted ? 'https' : 'http';
if (req.host.indexOf('roamnia-drsounds.c9users.io') != -1) {
protocol = 'https';
}
var index = fs.readFileSync(__dirname + '/client/index.html', 'utf8');
//index = index.replace('https://roamnia-drsounds.c9users.io', protocol + '://' + req.host + ':' + (process.env.PORT || 9261) + '');
//console.log(index);
res.write(index);
res.end();
} catch (e) {
throw e
res.send('error')
}
});
app.get('/', function (req, res) {
try {
var protocol = req.connection.encrypted ? 'https' : 'http';
if (req.host.indexOf('romnia-drsounds.c9users.io') != -1) {
protocol = 'https';
}
var index = fs.readFileSync(__dirname + '/client/index.html', 'utf8');
index = index.replace('https://roamnia-drsounds.c9users.io', protocol + '://' + req.host + ':' + (process.env.PORT || 9261) + '');
console.log(index);
res.write(index);
res.end();
} catch (e) {
res.write('error').end()
}
});
module.exports = app;
if (typeof require != 'undefined' && require.main==module) {
app.listen(process.env.PORT || 2858);
}