-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathserver.js
39 lines (26 loc) · 1.01 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
const fs = require('fs')
const path = require('path')
const express = require('express')
const proxyMiddleware = require('http-proxy-middleware')
const proxyTable = require('./build/proxy')
const uploadActions = require('./dep/jmui/upload/server.conf.js')
const config = require('./config/build.config.js').dev
const port = process.env.PORT || config.devServer.port
const resolve = file => path.resolve(__dirname, file)
const serve = (path, cache) => express.static(resolve(path))
const app = express()
// upload module
app.post("/uploads", uploadActions.onUpload);
app.delete("/uploads/:uuid", uploadActions.onDeleteFile);
Object.keys(proxyTable).forEach(context => {
const options = proxyTable[context]
app.use(proxyMiddleware(options.filter || context, options))
})
app.use('/dist', serve('./dist', true))
app.get('*', (req, res) => {
res.setHeader('Content-Type', 'text/html')
res.sendFile(resolve('./dist/index.html'))
})
app.listen(port, () => {
console.log(`server started at http://localhost:${port}`)
})