-
Notifications
You must be signed in to change notification settings - Fork 0
/
express-server.js
53 lines (45 loc) · 1.53 KB
/
express-server.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
"use strict"
let express = require('express')
let http = require('http')
let fs = require('fs')
let app = express()
let port = process.env.PORT ? +(process.env.PORT) : 3001
let default_host = process.env.HOST ? process.env.HOST : '10.0.0.219:80'
let endpoint = process.env.ENDPOINT ? process.env.ENDPOINT : `http://${default_host}/api/v2`
let ssoUrl = process.env.SSOURL ? process.env.SSOURL : `http://${default_host}/sso/index.php?redirect=${endpoint}/login/sso`
app.get('/dist/app.config.js', (req, res, next) => {
fs.readFile(`${__dirname}/dist/app.config.js`, 'utf8', (err, data) => {
if (err) { console.dir(err); next(err); return; }
res.contentType('application/javascript').send(
data.replace('$$endpoint$$', `${endpoint}`)
.replace('$$ssourl$$', `${ssoUrl}`)
)
})
})
app.use('/scripts', express.static(`${__dirname}/scripts`))
app.use('/styles', express.static(`${__dirname}/styles`))
app.use('/node_modules', express.static(`${__dirname}/node_modules`))
app.use('/dist', express.static(`${__dirname}/dist`))
app.use((req, res) => {
res.sendFile(`${__dirname}/index.html`)
})
var options = {
// key: fs.readFileSync(__dirname + '/server.key'),
// cert: fs.readFileSync(__dirname + '/server.crt')
}
module.exports = {
app: app
}
if (require.main === module) {
let parent = express()
parent.use(app)
var server = http.createServer(parent)
server.listen(port, err => {
if (err) {
console.error(err)
return process.exit(1)
} else {
console.log(`開始監聽 ${port}`)
}
})
}