-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
58 lines (50 loc) · 1.79 KB
/
server.js
File metadata and controls
58 lines (50 loc) · 1.79 KB
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
var express = require('express');
var execPath = process.env.PWD;
var fs = require('fs');
var cookieParser = require('cookie-parser');
var cookieSession = require('cookie-session');
var api = require('./api.js');
var app = express();
var bodyParser = require('body-parser');
app.use(bodyParser());
app.use(cookieParser());
app.use(cookieSession({
secret:'32425235235235',
name: 'session',
keys: ['key1', 'key2'],
cookie: {secure: false}
}));
app.use('/api', api.server);
app.use(express.static(__dirname + '/client/'));
app.get('/*', function (req, res) {
var protocol = req.connection.encrypted ? 'https' : 'http';
if (req.host.indexOf('liberal-drsounds.c9users.io') != -1) {
protocol = 'https';
}
var index = fs.readFileSync(__dirname + '/client/index.html', 'utf8');
//index = index.replace('https://liberal-drsounds.c9users.io', protocol + '://' + req.host + ':' + (process.env.PORT || 9261) + '');
//console.log(index);
res.write(index);
res.end();
});
app.get('/callback.html', function (req, res) {
var index = fs.readFileSync(__dirname + '/client/callback.html');
res.write(index);
res.end();
});
app.get('/', function (req, res) {
var protocol = req.connection.encrypted ? 'https' : 'http';
if (req.host.indexOf('liberal-drsounds.c9users.io') != -1) {
protocol = 'https';
}
var index = fs.readFileSync(__dirname + '/client/index.html', 'utf8');
index = index.replace('https://liberal-drsounds.c9users.io', protocol + '://' + req.host + ':' + (process.env.PORT || 9261) + '');
console.log(index);
res.write(index);
res.end();
});
app.use(express.static(__dirname + '/client/'));
module.exports = app;
if (typeof require != 'undefined' && require.main==module) {
app.listen(process.env.PORT || 9261);
}