-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
55 lines (46 loc) · 1.35 KB
/
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
54
55
const path = require('path')
const express = require('express')
const webpack = require('webpack')
const http = require('http')
const https = require('https')
const fs = require('fs-extra-promise')
const app = express()
const config = require('./webpack.dev.config')
const compiler = webpack(config)
app.use(
require('webpack-dev-middleware')(compiler, {
noInfo: true,
publicPath: '/'
})
)
app.use(require('webpack-hot-middleware')(compiler))
app.get('/libs/vendor.js', function (req, res) {
res.sendFile(path.join(__dirname, './libs/vendor.js'))
})
app.use('/libs', express.static('libs'))
function getUserHomeDir () {
return process.env.HOME || process.env.USERPROFILE
}
const options = {
key: fs.readFileSync(getUserHomeDir() + '/.tap/cert/server.key'),
cert: fs.readFileSync(getUserHomeDir() + '/.tap/cert/server.crt')
}
const httpServ = http.createServer(app)
const httpsServ = https.createServer(options, app)
const startHttps = () => {
httpsServ.listen(443, function () {
const env = process.env
const uid = parseInt(env['SUDO_UID'] || process.getuid(), 10)
const gid = parseInt(env['SUDO_GID'] || process.getgid(), 10)
process.setgid(gid)
process.setuid(uid)
console.log('443 is start up')
})
}
const start = () => {
httpServ.listen(80, function () {
console.log('80 is start up')
startHttps()
})
}
start()