-
Notifications
You must be signed in to change notification settings - Fork 5
/
app-static.js
executable file
·59 lines (44 loc) · 1.48 KB
/
app-static.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
'use strict';
var https = require('https');
var koa = require('koa');
var app = koa();
var fs = require('fs');
var statics = require('koa-static');
var mount = require('koa-mount');
// var serve = require('koa-serve');
var a = koa();
/** Access-Control-Allow-Origin */
var cors = require('koa-cors');
var enforceHttps = require('koa-sslify');
var config = require('./config');
var staticPort = config.staticPort;
var env = config.env;
//https option
var options = {
key: fs.readFileSync('keys/server.key'),
cert: fs.readFileSync('keys/server.crt'),
port: 8091
};
module.exports = function () {
if (env) {
app.use(cors());
// app.use(enforceHttps(options));
/** static file folder */
// app.use(serve('/static', __dirname + '/public/app/dest/'));
// app.use(mount('/static', statics(__dirname + '/public/app/dest/')));
a.use(statics(__dirname + '/public/'));
app.use(mount('/static', a));
// app.use(statics(__dirname + '/public/app/dest/'));
if (config.env === 'prd') {
app.listen(staticPort);
// console.log('static on ' + staticPort);
console.log(`static: http://${config.ip}:${config.staticPort}`)
}
if (config.env === 'dev') {
//https
https.createServer(options, app.callback()).listen(config.staticPorts, function () {
console.log(`static: http://${config.ip}:${config.staticPorts}`)
});
}
}
}