forked from netease-kit/NIM_Web_Demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
61 lines (53 loc) · 1.69 KB
/
app.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
var express = require('express');
var https = require('https');
var http = require('http');
var fs = require('fs');
var prettyjson = require('prettyjson');
var multer = require('multer');
var app = express();
app.use(express.static('./'));
app.use(express.static('node_modules'));
app.use(function (req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET, HEAD, POST, PUT, DELETE, OPTIONS');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, AppKey, Nonce, CurTime, CheckSum');
// res.header('Access-Control-Max-Age', 604800);
res.header('Access-Control-Allow-Credentials', true);
next();
});
// app.use(function (req, res, next) {
// res.status(404).send('404')
// })
app.get('timeout', function (req, res) {
console.log('timeout');
});
var options = {
key: fs.readFileSync('./ssh/key.pem'),
cert: fs.readFileSync('./ssh/cert.pem')
};
var httpServer = http.createServer(app);
httpServer.listen(8182, function () {
console.info('server start at ' + 8182)
logAddress(httpServer, 'http');
});
var httpsServer = https.createServer(options, app);
httpsServer.listen(7182, function () {
logAddress(httpsServer, 'https');
});
function logAddress(server, type) {
var address = server.address();
address = type + '://localhost:' + address.port;
// console.log('vcloud');
// console.log(address + '/webdemo/vcloud/room.html?type=edu&roomid=36168');
log();
}
function log(obj) {
if (!obj) return
if (typeof obj === 'string') {
if (obj.length > 100) {
return;
}
obj = [obj];
}
console.log(prettyjson.render(obj));
}