-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fastify-autoload): add fastify-autoload
update build script to compile & bundle all ts files
- Loading branch information
Showing
9 changed files
with
201 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Plugins Folder | ||
|
||
Plugins define behavior that is common to all the routes in your | ||
application. Authentication, caching, templates, and all the other cross | ||
cutting concerns should be handled by plugins placed in this folder. | ||
|
||
Files in this folder are typically defined through the | ||
[`fastify-plugin`](https://github.com/fastify/fastify-plugin) module, | ||
making them non-encapsulated. They can define decorators and set hooks | ||
that will then be used in the rest of your application. | ||
|
||
Check out: | ||
|
||
- [The hitchhiker's guide to plugins](https://www.fastify.io/docs/latest/Plugins-Guide/) | ||
- [Fastify decorators](https://www.fastify.io/docs/latest/Decorators/). | ||
- [Fastify lifecycle](https://www.fastify.io/docs/latest/Lifecycle/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import fp from 'fastify-plugin' | ||
import sensible, { SensibleOptions } from 'fastify-sensible' | ||
|
||
/** | ||
* This plugins adds some utilities to handle http errors | ||
* | ||
* @see https://github.com/fastify/fastify-sensible | ||
*/ | ||
export default fp<SensibleOptions>(async (fastify, opts) => { | ||
fastify.register(sensible, { | ||
errorHandler: false | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import fp from 'fastify-plugin' | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface SupportPluginOptions { | ||
// Specify Support plugin options here | ||
} | ||
|
||
// The use of fastify-plugin is required to be able | ||
// to export the decorators to the outer scope | ||
export default fp<SupportPluginOptions>(async (fastify, opts) => { | ||
fastify.decorate('someSupport', function () { | ||
return 'hugs' | ||
}) | ||
}) | ||
|
||
// When using .decorate you have to specify added properties for Typescript | ||
declare module 'fastify' { | ||
export interface FastifyInstance { | ||
someSupport(): string | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Routes Folder | ||
|
||
Routes define endpoints 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 routes that define the endpoints | ||
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 routes within a single monolith, | ||
and eventually extract them. | ||
|
||
If you need to share functionality between routes, place that | ||
functionality into the `plugins` folder, and share it via | ||
[decorators](https://www.fastify.io/docs/latest/Decorators/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { FastifyPluginAsync } from 'fastify' | ||
|
||
const example: FastifyPluginAsync = async (fastify, opts): Promise<void> => { | ||
fastify.get('/', async function (request, reply) { | ||
return 'this is an example' | ||
}) | ||
} | ||
|
||
export default example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { FastifyPluginAsync } from 'fastify' | ||
|
||
const root: FastifyPluginAsync = async (fastify, opts): Promise<void> => { | ||
fastify.get('/', async function (request, reply) { | ||
return { root: true } | ||
}) | ||
} | ||
|
||
export default root |