-
Notifications
You must be signed in to change notification settings - Fork 7
/
app.js
75 lines (65 loc) · 1.42 KB
/
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import path from 'path'
import express from 'express'
import api_item from './api/item.js'
import api_raw from './api/raw.js'
import api_text from './api/text.js'
import api_thumbnail from './api/thumbnail.js'
const __dirname = path.resolve()
const app = express()
process.on('uncaughtException', (e) => {
console.error('Node.js process error.\n', e)
})
app.use((req, res, next) => {
res.setTimeout(10 * 1000, () => {
console.error('Request timeout.')
return res.status(408).send('Request Timeout.')
})
next()
})
app.use(express.static('public'))
app.get('/api/item', (req, res) => {
console.log(req.url)
try {
api_item(req, res)
} catch (e) {
res.status(500).send()
console.error(e)
// throw e
}
})
app.get('/api/raw*', (req, res) => {
console.log(req.url)
try {
api_raw(req, res)
} catch (e) {
res.status(500).send()
console.error(e)
// throw e
}
})
app.get('/api/text', (req, res) => {
console.log(req.url)
try {
api_text(req, res)
} catch (e) {
res.status(500).send()
console.error(e)
// throw e
}
})
app.get('/api/thumbnail', (req, res) => {
console.log(req.url)
try {
api_thumbnail(req, res)
} catch (e) {
res.status(500).send()
console.error(e)
// throw e
}
})
app.get('/((?!api)*)', (req, res) => {
console.log(req.url)
res.sendFile(`${__dirname}/public/index.html`)
})
console.info('http://localhost:3000')
app.listen(3000)