Chapter 4,6: prettier updates and web framework samples
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
# Services Folder
|
||||
|
||||
Services define routes within your application. Fastify provides an
|
||||
easy path to a microservice architecture, in the future you might want
|
||||
to independently deploy some of those.
|
||||
|
||||
In this folder you should define all the services that define the routes
|
||||
of your web application.
|
||||
Each service is a [Fastify
|
||||
plugin](https://www.fastify.io/docs/latest/Plugins/), it is
|
||||
encapsulated (it can have its own independent plugins) and it is
|
||||
typically stored in a file; be careful to group your routes logically,
|
||||
e.g. all `/users` routes in a `users.js` file. We have added
|
||||
a `root.js` file for you with a '/' root added.
|
||||
|
||||
If a single file become too large, create a folder and add a `index.js` file there:
|
||||
this file must be a Fastify plugin, and it will be loaded automatically
|
||||
by the application. You can now add as many files as you want inside that folder.
|
||||
In this way you can create complex services within a single monolith,
|
||||
and eventually extract them.
|
||||
|
||||
If you need to share functionality between services, place that
|
||||
functionality into the `plugins` folder, and share it via
|
||||
[decorators](https://www.fastify.io/docs/latest/Decorators/).
|
||||
@@ -0,0 +1,17 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = function (fastify, opts, next) {
|
||||
fastify.get('/example', function (request, reply) {
|
||||
reply.send('this is an example')
|
||||
})
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
// If you prefer async/await, use the following
|
||||
//
|
||||
// module.exports = async function (fastify, opts) {
|
||||
// fastify.get('/example', async function (request, reply) {
|
||||
// return 'this is an example'
|
||||
// })
|
||||
// }
|
||||
@@ -0,0 +1,17 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = function (fastify, opts, next) {
|
||||
fastify.get('/', function (request, reply) {
|
||||
reply.send({ root: true })
|
||||
})
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
// If you prefer async/await, use the following
|
||||
//
|
||||
// module.exports = async function (fastify, opts) {
|
||||
// fastify.get('/', async function (request, reply) {
|
||||
// return { root: true }
|
||||
// })
|
||||
// }
|
||||
Reference in New Issue
Block a user