forked from unliar/oss-element-upload
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
47 lines (40 loc) · 964 Bytes
/
app.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
const express = require("express")
const path = require('path')
const bodyParser = require("body-parser")
const router = require("./router")
const app = express()
const http = require("http")
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({
extended: false
}))
console.log(path.join(__dirname, 'fe'))
app.use("/demo", express.static(path.join(__dirname, 'fe')))
app.use("/api", router)
app.use((req, res, next) => {
const err = new Error("not Found")
err.status = 404
next(err)
})
app.use((err, req, res, next) => {
console.log(err)
res.status(err.status || 500)
res.json({
statusCode: err.status || 500,
message: `errors`,
result: `${err}`
})
next()
})
const port = 2050
app.set("port", port)
const onError = err => {
console.log(err)
}
const onListen = () => {
console.log(server.address())
}
const server = http.createServer(app)
server.listen(port)
server.on("error", onError)
server.on("listening", onListen)