website/server.js
2019-11-19 07:52:41 +01:00

69 lines
1.4 KiB
JavaScript

//! Deps
const express = require('express');
const helmet = require('helmet');
const compression = require('compression');
const cors = require('cors');
const morgan = require('morgan');
const chalk = require('chalk');
var hbs = require('express-handlebars');
let { port, hostname } = {
port: 3621
// hostname: 'localhost'
};
const app = express();
app.set('view engine', 'hbs');
app.engine(
'hbs',
hbs({
extname: 'hbs',
defaultView: 'default'
})
);
app.set('json spaces', 4);
app.use('/assets', express.static('./assets'));
app.set('view options', {
layout: false
});
app.use(express.json());
app.use(
express.urlencoded({
extended: true
})
);
app.use(helmet());
app.use(compression());
app.use(cors());
// Logging
app.use(
morgan((tokens, req, res) => {
return [
chalk.hex('#34ace0').bold(tokens.method(req, res)),
chalk.hex('#ffb142').bold(tokens.status(req, res)),
chalk.hex('#ff5252').bold(req.hostname + tokens.url(req, res)),
chalk.hex('#2ed573').bold(tokens['response-time'](req, res) + 'ms'),
chalk.hex('#f78fb3').bold('@ ' + tokens.date(req, res))
].join(' ');
})
);
app.use('/lore', require('./routes/lore'));
module.exports = (client) => {
app.get('/', async (req, res) => {
res.render('index', {
layout: 'main',
link: 'ry'
});
});
app.listen(
port,
/* hostname, */ () => {
setTimeout(() => {
console.log(`Listening on ${port}`);
}, 1000 * 3);
}
);
};