-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
75 lines (62 loc) · 1.81 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
const express = require('express')
const cors = require('cors')
const nunjucks = require('nunjucks')
const open = require('open')
const computerName = require('computer-name')
const fileUpload = require('express-fileupload')
const localtunnel = require('localtunnel')
const app = express()
const PORT = process.env.PORT || 3069
const nunjucksEnv = nunjucks.configure('html', {
autoescape: true,
express: app
})
nunjucksEnv.addFilter('toLocaleString', (num) => Number(num).toLocaleString('en'))
nunjucksEnv.addFilter('toLocaleDateString', (s) => {
let date = new Date(s)
return date.toLocaleDateString('en-US')
})
nunjucksEnv.addFilter('trim', (str) => str.trim())
nunjucksEnv.addFilter('stripWhitespace', (str) => {
if (str)
return str.split(' ').join('')
return null
})
nunjucksEnv.addFilter('getRatingIsChecked', (rating, starNumber) => {
if (rating == starNumber)
return 'checked'
return null
})
nunjucksEnv.addFilter('is_string', obj => {
return typeof obj == 'string';
})
nunjucksEnv.addFilter('convertCssProperty', str => {
return str.replaceAll('_', '-')
})
app.use(fileUpload({
createParentPath: true
}))
app.use(cors())
app.use(
express.urlencoded({
extended: true
})
)
app.use(express.json())
app.engine('html', nunjucks.render)
app.set('view_engine', 'html')
app.use('/', require('./api/index'))
app.use(express.static(__dirname + '/'))
app.use('/webnovel', require('./api/webnovel'))
app.use(express.static('./css'))
app.use(express.static('./js'))
app.use(express.static('./settings'))
app.use('/fonts', express.static('./fonts'))
app.use('/img', express.static('./img'))
app.listen(PORT, () => {
console.log(`The Server is running at: http://localhost:${PORT}/`)
})
open(`http://${computerName()}:${PORT}`)
// localtunnel({ port: PORT }).then((tunnel) => {
// console.log(tunnel.url)
// })