fatsify核心功能示例测试!!!
This commit is contained in:
38
node_modules/fastify/examples/route-prefix.js
generated
vendored
Normal file
38
node_modules/fastify/examples/route-prefix.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
'use strict'
|
||||
|
||||
const fastify = require('../fastify')({ logger: true })
|
||||
|
||||
const opts = {
|
||||
schema: {
|
||||
response: {
|
||||
'2xx': {
|
||||
type: 'object',
|
||||
properties: {
|
||||
greet: { type: 'string' }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fastify.register(function (instance, options, done) {
|
||||
// the route will be '/english/hello'
|
||||
instance.get('/hello', opts, (req, reply) => {
|
||||
reply.send({ greet: 'hello' })
|
||||
})
|
||||
done()
|
||||
}, { prefix: '/english' })
|
||||
|
||||
fastify.register(function (instance, options, done) {
|
||||
// the route will be '/italian/hello'
|
||||
instance.get('/hello', opts, (req, reply) => {
|
||||
reply.send({ greet: 'ciao' })
|
||||
})
|
||||
done()
|
||||
}, { prefix: '/italian' })
|
||||
|
||||
fastify.listen({ port: 8000 }, function (err) {
|
||||
if (err) {
|
||||
throw err
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user