-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
32 lines (26 loc) · 958 Bytes
/
app.js
File metadata and controls
32 lines (26 loc) · 958 Bytes
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
const express = require(`express`)
const bodyParser = require('body-parser')
// const compression = require('compression')
const app = express()
app.use(express.json())
// app.use(compression())
app.use(bodyParser.urlencoded({
extended: false
}))
app.use(require('./logger'))
app.use('/api',require('./router/router'))
// 版块列表
app.use('/api/forumlist/',express.static('./src/forumlist.json'))
app.all('*', function (req, res, next) {
res.header('Access-Control-Allow-Origin', '*')
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept')
res.header('Access-Control-Allow-Metheds', 'PUT, POST, GET, DELETE, OPTIONS')
res.header('X-Powered-By', 'nodejs')
res.header('Content-Type', 'application/json;charset=utf-8');
next();
})
var hostName = '127.0.0.1'
var port = process.env.PORT || 80
app.listen(port, () => {
console.log(`服务器运行在 http://${hostName}:${port}`);
})