OTM/server.js

59 lines
1.1 KiB
JavaScript
Raw Normal View History

2021-07-16 09:12:30 +02:00
const fastify = require('fastify')();//{ logger: true });
const path = require('path');
const crypto = require('crypto');
const csass = require("./compile_sass").compileSassMain();
2021-07-16 11:48:27 +02:00
fastify.register(require('fastify-static'), {
2021-07-16 09:12:30 +02:00
root: path.join(__dirname, 'public'),
prefix: '/public/',
2021-07-16 11:48:27 +02:00
});
2021-07-16 09:12:30 +02:00
fastify.register(require('fastify-leveldb'), {
name: 'db'
}, err => {
if (err) throw err
});
fastify.get('/', (req, reply) => {
2021-07-16 11:48:27 +02:00
reply.sendFile('/template/home.html');
2021-07-16 09:12:30 +02:00
});
fastify.get('/dbg', (req, reply) => {
2021-07-16 11:48:27 +02:00
reply.sendFile('/template/templates.html');
2021-07-16 09:12:30 +02:00
});
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){
2021-07-16 11:48:27 +02:00
reply.sendFile('/template/journey.html');
2021-07-16 09:12:30 +02:00
}
});
fastify.register(require('./router/api'), { prefix: '/api' });
fastify.listen(8080,'0.0.0.0' ,(err,address) => {
if (err) throw err;
console.log("Listening on", address);
});