Migrate to pug

This commit is contained in:
soraefir
2023-06-25 12:26:17 +02:00
parent 0693d47939
commit 681975a44b
54 changed files with 688 additions and 22868 deletions

View File

@@ -1,8 +1,6 @@
const fastify = require('fastify')();//{ logger: true });
const path = require('path');
const csass = require("./compile_sass").compileSassMain();
fastify.register(require('@fastify/static'), {
root: path.join(__dirname, 'public'),
prefix: '/public/',
@@ -14,37 +12,21 @@ fastify.register(require('@fastify/leveldb'), {
if (err) throw err
});
fastify.register(require("@fastify/view"), {
engine: {
pug: require("pug"),
},
});
fastify.get('/', (req, reply) => reply.sendFile('/template/home.html'));
fastify.register(require('./router/api'), { prefix: '/api' });
fastify.get('/:id', (req, reply) => {
try{
const ec = parseInt(req.params.id);
switch(ec){
case 400:
case 401:
case 402:
case 403:
case 404:
case 405:
reply.code(ec).send("Client Error");
break;
case 500:
reply.code(ec).send("Internal Error");
break;
default:
throw undefined;
}
}catch(e){
reply.sendFile('/template/journey.html');
}
});
fastify.get('/view/:id', (req, reply) => reply.sendFile('/template/journey.html'));
fastify.get('/short/:id', (req, reply) => reply.sendFile('/template/journey.html'));
fastify.get('/', (req, reply) => reply.view("/template/home.pug", ));
fastify.get('/:id', (req, reply) => reply.view('/template/journey.pug'));
fastify.get('/view/:id', (req, reply) => reply.view('/template/view.pug'));
fastify.get('/short/:id', (req, reply) => reply.view('/template/short.pug'));
fastify.listen({port:8080,host:'0.0.0.0'} ,(err,address) => {