This repository has been archived by the owner on Jun 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
server.js
76 lines (60 loc) · 1.81 KB
/
server.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 port = process.env['PORT'] || 8080
const express = require('express')
const path = require('path')
const https = require('https')
const fs = require('fs')
const app = express()
const utils = require('./utils')
app.set('view engine', 'pug')
app.use(require('body-parser').urlencoded({ extended: false }))
app.use(require('body-parser').json())
app.use(require('cookie-parser')())
app.use(express.static('static'))
app.use('/css', require('postcss-middleware')({
src: (req) => {
const splitPath = req.path.split('/')
const file = splitPath.pop().split('.')
file.pop()
return path.join(__dirname, 'static', 'css', splitPath.join('/'), `${file}.pcss`)
},
plugins: [
require('tailwindcss')('tailwind.config.js'),
require('autoprefixer')(),
require('postcss-import')(),
require('postcss-nested')()
]
}))
app.get('*', (req, res, next) => {
console.log(`Requested ${req.path}...`)
next()
})
app.get('/', function (req, res) {
if (req.cookies['userAuth'])
return res.redirect('/b/accounts')
res.render('landing', {
query: req.query,
...utils.basicData(req)
})
})
app.use('/a', require('./apps/userauth'))
app.use('/b', require('./apps/banking'))
app.use('/api', require('./apps/api'))
app.use('/pages', require('./apps/pages'))
app.get('*', function (req, res, next) {
res.render('error', {
error: '404',
...utils.basicData(req)
})
})
app.use((err, req, res, next) => {
res.render('error', {
error: err.message || err.msg || err || 'Unknown error',
...utils.basicData(req)
})
})
https.createServer({
key: fs.readFileSync('server.key'),
cert: fs.readFileSync('server.cert')
}, app).listen(port, () => {
console.log(`Https server is listening! Port: ${port}`)
})