qwik-account-manager/index.js

44 lines
1012 B
JavaScript
Raw Normal View History

2022-01-31 20:47:34 +01:00
import cookieParser from 'cookie-parser'
import crypto from 'crypto'
2022-01-15 20:40:41 +01:00
import { dbInit } from './libs/database.js'
2022-01-15 18:47:56 +01:00
import dotenv from 'dotenv'
2022-01-15 19:27:18 +01:00
import express from 'express'
2022-01-15 20:40:41 +01:00
import njk from 'nunjucks'
2022-01-15 19:27:18 +01:00
import ROUTES from './routes/routes.js'
2022-01-15 18:47:56 +01:00
dotenv.config()
2022-01-15 19:27:18 +01:00
const APP = express()
const PORT = process.env.PORT ?? 12345
2022-01-15 18:47:56 +01:00
2022-01-23 15:52:12 +01:00
await dbInit()
.then(
() => console.log("Connected to database!")
).catch(
2022-01-31 20:03:04 +01:00
err => {
console.log("Error occured!")
console.dir(err, { depth: null })
}
2022-01-23 15:52:12 +01:00
)
2022-01-15 18:47:56 +01:00
2022-01-31 20:47:34 +01:00
APP.use(cookieParser(process.env.CK_SECRET ?? crypto.generateKeySync("aes", { length: 128 }).export().toString(), {}))
2022-01-15 19:27:18 +01:00
APP.use(express.urlencoded({ extended: true }))
APP.use('/static', express.static('static'))
2022-01-15 18:47:56 +01:00
2022-01-15 19:27:18 +01:00
APP.use('/', ROUTES)
2022-01-15 18:47:56 +01:00
2022-01-15 20:40:41 +01:00
njk.configure(
'views',
{
2022-04-21 20:48:02 +02:00
autoescape: true,
2022-01-15 20:40:41 +01:00
lstripBlocks: true,
2022-04-21 20:48:02 +02:00
trimBlocks: true,
express: APP,
2022-01-15 20:40:41 +01:00
}
)
2022-01-15 19:27:18 +01:00
APP.listen(
PORT,
() => console.log('Server started at http://localhost:' + PORT)
)