linkylinky/src/server.js

32 lines
639 B
JavaScript

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()