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
|
2022-11-02 14:29:46 -04:00
|
|
|
(async () => {
|
|
|
|
const db = require('./src/models');
|
2022-11-03 12:26:45 -04:00
|
|
|
await db.sequelize.sync({ alter: true });
|
2022-11-02 14:29:46 -04:00
|
|
|
})();
|
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);
|
2022-11-03 12:26:45 -04:00
|
|
|
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}`);
|
|
|
|
});
|