| 'use strict' |
| |
| constfastify=require('fastify')({logger: false,trustProxy: true}) |
| constredis=require('redis').createClient({host: 'localhost',port: 6379}) |
| constpath=require('path') |
| consthelmet=require('fastify-helmet') |
| require('dotenv').config() |
| |
| fastify |
| .register(require('fastify-static'),{ |
| root: path.join(__dirname,'public'), |
| prefix: '/public/', |
| }).register(helmet,{contentSecurityPolicy: false}) |
| |
| fastify.get('/',async(request,reply)=>{ |
| let{ ip }=request |
| letstrTemplate=`New visitor ${ip}` |
| redis.lpush("visitors",strTemplate) |
| |
| reply.sendFile('TeamBazinga.html') |
| }) |
| |
| // js and css files |
| fastify.get('/css/home',asyncfunction(request,reply){ |
| reply.sendFile('bazinga.css') |
| }) |
| |
| // reveal Js -> https://revealjs.com/ |
| fastify.get('/js/reveal',asyncfunction(request,reply){ |
| reply.sendFile('/dist/reveal.js') |
| }) |
| fastify.get('/css/revealReset',asyncfunction(request,reply){ |
| reply.sendFile('/dist/reset.css') |
| }) |
| fastify.get('/css/reveal',asyncfunction(request,reply){ |
| reply.sendFile('/dist/reveal.css') |
| }) |
| fastify.get('/css/revealMoon',asyncfunction(request,reply){ |
| reply.sendFile('/dist/theme/moon.css') |
| }) |
| |
| |
| |
| conststart=async()=>{ |
| const{PORT}=process.env |
| |
| try{ |
| awaitfastify.listen(PORT) |
| console.log(`server listening on ${fastify.server.address().port}`) |
| }catch(err){ |
| fastify.log.error(err) |
| process.exit(1) |
| } |
| } |
| start() |