website/server.js

70 lines
1.4 KiB
JavaScript
Raw Normal View History

2019-11-15 16:51:24 +00:00
//! Deps
2019-11-19 06:52:41 +00:00
const express = require('express');
const helmet = require('helmet');
const compression = require('compression');
const cors = require('cors');
const morgan = require('morgan');
const chalk = require('chalk');
2019-11-15 16:51:24 +00:00
var hbs = require('express-handlebars');
2019-11-19 06:52:41 +00:00
let { port, hostname } = {
port: 3621
// hostname: 'localhost'
};
2019-11-15 16:51:24 +00:00
2019-11-19 06:52:41 +00:00
const app = express();
2019-11-15 16:51:24 +00:00
app.set('view engine', 'hbs');
2019-11-19 06:52:41 +00:00
app.engine(
'hbs',
hbs({
extname: 'hbs',
defaultView: 'default'
})
);
2019-11-15 16:51:24 +00:00
app.set('json spaces', 4);
2019-11-19 06:52:41 +00:00
app.use('/assets', express.static('./assets'));
2019-11-15 16:51:24 +00:00
app.set('view options', {
2019-11-19 06:52:41 +00:00
layout: false
2019-11-15 16:51:24 +00:00
});
app.use(express.json());
2019-11-19 06:52:41 +00:00
app.use(
express.urlencoded({
extended: true
})
);
2019-11-15 16:51:24 +00:00
app.use(helmet());
app.use(compression());
app.use(cors());
// Logging
app.use(
2019-11-19 06:52:41 +00:00
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(' ');
})
2019-11-15 16:51:24 +00:00
);
2019-11-19 06:52:41 +00:00
app.use('/lore', require('./routes/lore'));
2019-11-15 16:51:24 +00:00
2019-11-19 06:52:41 +00:00
module.exports = (client) => {
app.get('/', async (req, res) => {
res.render('index', {
layout: 'main',
link: 'ry'
});
});
2019-11-15 16:51:24 +00:00
2019-11-19 06:52:41 +00:00
app.listen(
port,
/* hostname, */ () => {
setTimeout(() => {
console.log(`Listening on ${port}`);
}, 1000 * 3);
}
);
};