qwik-account-manager/index.js

44 lines
1012 B
JavaScript

import cookieParser from 'cookie-parser'
import crypto from 'crypto'
import { dbInit } from './libs/database.js'
import dotenv from 'dotenv'
import express from 'express'
import njk from 'nunjucks'
import ROUTES from './routes/routes.js'
dotenv.config()
const APP = express()
const PORT = process.env.PORT ?? 12345
await dbInit()
.then(
() => console.log("Connected to database!")
).catch(
err => {
console.log("Error occured!")
console.dir(err, { depth: null })
}
)
APP.use(cookieParser(process.env.CK_SECRET ?? crypto.generateKeySync("aes", { length: 128 }).export().toString(), {}))
APP.use(express.urlencoded({ extended: true }))
APP.use('/static', express.static('static'))
APP.use('/', ROUTES)
njk.configure(
'views',
{
autoescape: true,
lstripBlocks: true,
trimBlocks: true,
express: APP,
}
)
APP.listen(
PORT,
() => console.log('Server started at http://localhost:' + PORT)
)