overseer/index.js

56 lines
1.5 KiB
JavaScript
Raw Permalink Normal View History

2022-11-01 23:55:07 -04:00
const express = require('express');
const session = require('express-session');
2022-11-04 17:54:43 -04:00
// const flash = require('express-flasher');
2022-11-01 23:55:07 -04:00
// instantiate new express.js app
const app = express();
const config = require('config');
2022-11-01 23:55:07 -04:00
2022-11-02 13:45:40 -04:00
// initialize database connection
(async () => {
const db = require('./src/models');
2022-11-03 22:28:01 -04:00
await db.sequelize.sync({
alter: true,
});
})();
2022-11-02 13:45:40 -04:00
// initialize express.js session
app.use(session({
resave: false, // don't save session if unmodified
saveUninitialized: false, // don't create session until something stored
secret: 'lord of the rings',
}));
// setup flash messaging
2022-11-04 17:54:43 -04:00
// app.use(flash.flash());
// app.use(flash.flashRead());
2022-11-02 13:45:40 -04:00
// set up body POST parameters
app.use(express.json());
2022-11-03 22:28:01 -04:00
app.use(express.urlencoded({
extended: true,
}));
2022-11-02 13:45:40 -04:00
2022-11-01 23:55:07 -04:00
// load the template engine
app.set('view engine', 'twig');
// enable static file serving
app.use(express.static('public'));
// load route handlers
const homeRoutes = require('./src/routes/home');
2022-11-02 13:45:40 -04:00
const itemRoutes = require('./src/routes/item');
2022-11-01 23:55:07 -04:00
// register route handlers
app.get('/', homeRoutes.getIndex);
2022-11-02 13:45:40 -04:00
app.get('/item/add', itemRoutes.getAdd);
app.post('/item/add', itemRoutes.postAdd);
app.get('/item/:id', itemRoutes.getItem);
2022-11-03 22:08:45 -04:00
app.get('/item/:id/edit', itemRoutes.getItemEdit);
app.post('/item/:id/edit', itemRoutes.postItemEdit);
2022-11-01 23:55:07 -04:00
// start app
app.listen(config.get('server.port'), config.get('server.address'), () => {
console.log(`Overseer is listening on port ${config.get('server.port')}.`);
2022-11-01 23:55:07 -04:00
});