import express from 'express'; import createError from 'http-errors'; import annotationsRouter from './routes/router.js'; import { create } from 'express-handlebars'; import { annotationHbsParams } from './routes/render/renderAnnotation.js'; import { fileURLToPath } from 'url'; var app = express(); // view engine setup app.set('views', fullPath('views')); const hbs = create({ extname: 'hbs', helpers: { annotationHbsParams(arg) { return annotationHbsParams(arg, false); }, }, }); app.engine('hbs', hbs.engine); app.set('view engine', 'hbs'); app.use(express.json({ type: ['application/json', 'application/ld+json'] })); app.use(express.urlencoded({ extended: false })); app.use(express.static(fullPath('public'))); app.use('/', annotationsRouter); // catch 404 and forward to error handler app.use(function (req, res, next) { next(createError(404)); }); // error handler app.use(function (err, req, res, next) { // set locals, only providing error in development res.locals.message = err.message; res.locals.error = req.app.get('env') === 'development' ? err : {}; // render the error page res.status(err.status || 500); res.render('error'); }); export default app; function fullPath(filename: string): string { return fileURLToPath(new URL(filename, import.meta.url)); }