First routes

This commit is contained in:
Nicolai Ort 2021-08-12 19:10:36 +02:00
parent b7354e505b
commit e5c302aec8
Signed by: niggl
GPG Key ID: 13AFA55AF62F269F
1 changed files with 32 additions and 0 deletions

32
src/server.js Normal file
View File

@ -0,0 +1,32 @@
const fastify = require('fastify')({ logger: true })
// Declare a route
fastify.get('/', async (request, reply) => {
return { hello: 'world' }
})
fastify.get('/a/:id', async (req, res)=>{
res.redirect(302, `https://amazon.de/dp/${req.params.id}`)
})
fastify.get('/:id', async (req, res)=>{
res.statusCode = 301;
return req.params.id;
})
fastify.post('/new', async (req, res) =>{
console.log(req.body);
return "";
})
// Run the server!
const start = async () => {
try {
await fastify.listen(3000)
} catch (err) {
fastify.log.error(err)
process.exit(1)
}
}
start()