UNPKG

807 BJavaScriptView Raw
1'use strict'
2
3const fastify = require('../fastify')()
4
5const opts = {
6 schema: {
7 response: {
8 '2xx': {
9 type: 'object',
10 properties: {
11 greet: { type: 'string' }
12 }
13 }
14 }
15 }
16}
17
18fastify.register(function (instance, options, next) {
19 // the route will be '/english/hello'
20 instance.get('/hello', opts, (req, reply) => {
21 reply.send({ greet: 'hello' })
22 })
23 next()
24}, { prefix: '/english' })
25
26fastify.register(function (instance, options, next) {
27 // the route will be '/italian/hello'
28 instance.get('/hello', opts, (req, reply) => {
29 reply.send({ greet: 'ciao' })
30 })
31 next()
32}, { prefix: '/italian' })
33
34fastify.listen(8000, function (err) {
35 if (err) {
36 throw err
37 }
38 console.log(`server listening on ${fastify.server.address().port}`)
39})