OTM/server.js
choelzl dbf93d8d1f
All checks were successful
continuous-integration/drone/push Build is passing
fixes
2021-07-16 12:02:23 +02:00

55 lines
1.0 KiB
JavaScript

const fastify = require('fastify')();//{ logger: true });
const path = require('path');
const crypto = require('crypto');
const csass = require("./compile_sass").compileSassMain();
fastify.register(require('fastify-static'), {
root: path.join(__dirname, 'public'),
prefix: '/public/',
});
fastify.register(require('fastify-leveldb'), {
name: 'db'
}, err => {
if (err) throw err
});
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.listen(8080,'0.0.0.0' ,(err,address) => {
if (err) throw err;
console.log("Listening on", address);
});