First routes
This commit is contained in:
parent
b7354e505b
commit
e5c302aec8
|
@ -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()
|
Loading…
Reference in New Issue