forked from xiaokaike/vue-color
-
Notifications
You must be signed in to change notification settings - Fork 0
/
localServer.js
33 lines (26 loc) · 859 Bytes
/
localServer.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
const express = require('express')
const path = require('path')
/* eslint-disable new-cap */
const app = new express()
/* eslint-enable new-cap */
const config = require('./config')
const port = process.env.PORT || 3000
app.use(express.static('client'))
/**
* Note: Generally we don't need an application server for serving
* static files; instead we can use a web server such as nginx for static resources.
*/
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*')
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept')
next()
})
app.get('/static/*', (req, res) => {
res.sendFile(path.join(config.build.assetsRoot, req.path))
})
app.get('*', (req, res) => {
res.sendFile(config.build.index)
})
app.listen(port, () => {
console.log(`local server listening on port ${port}`)
})