overseer/index.js

37 lines
894 B
JavaScript
Raw Normal View History

2022-11-01 23:55:07 -04:00
const express = require('express');
// instantiate new express.js app
const app = express();
const port = 3000;
2022-11-02 13:45:40 -04:00
// initialize database connection
(async () => {
const db = require('./src/models');
await db.sequelize.sync({ alter: true });
})();
2022-11-02 13:45:40 -04:00
// set up body POST parameters
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
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-01 23:55:07 -04:00
// start app
app.listen(port, () => {
console.log(`Example app listening on port ${port}`);
});