-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(node): create fastify setup closer to what fastify-cli creates (#…
- Loading branch information
Showing
7 changed files
with
80 additions
and
13 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
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
24 changes: 20 additions & 4 deletions
24
packages/node/src/generators/application/files/fastify/src/app/app.ts__tmpl__
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 |
---|---|---|
@@ -1,11 +1,27 @@ | ||
import * as path from 'path'; | ||
import { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify'; | ||
import AutoLoad from '@fastify/autoload'; | ||
|
||
/* eslint-disable-next-line */ | ||
export interface AppOptions { | ||
} | ||
export interface AppOptions { } | ||
|
||
export async function app(fastify: FastifyInstance, opts: AppOptions) { | ||
fastify.get('/', async function(request: FastifyRequest, reply: FastifyReply) { | ||
return { message: 'Hello API' }; | ||
// Place here your custom code! | ||
|
||
// Do not touch the following lines | ||
|
||
// This loads all plugins defined in plugins | ||
// those should be support plugins that are reused | ||
// through your application | ||
fastify.register(AutoLoad, { | ||
dir: path.join(__dirname, 'plugins'), | ||
options: { ...opts }, | ||
}); | ||
|
||
// This loads all plugins defined in routes | ||
// define your routes in one of these | ||
fastify.register(AutoLoad, { | ||
dir: path.join(__dirname, 'routes'), | ||
options: { ...opts }, | ||
}); | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/node/src/generators/application/files/fastify/src/app/plugins/sensible.ts__tmpl__
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,12 @@ | ||
import { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify'; | ||
import fp from 'fastify-plugin'; | ||
import sensible from '@fastify/sensible'; | ||
|
||
/** | ||
* This plugins adds some utilities to handle http errors | ||
* | ||
* @see https://github.com/fastify/fastify-sensible | ||
*/ | ||
export default fp(async function(fastify: FastifyInstance) { | ||
fastify.register(sensible); | ||
}); |
7 changes: 7 additions & 0 deletions
7
packages/node/src/generators/application/files/fastify/src/app/routes/root.ts__tmpl__
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,7 @@ | ||
import { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify'; | ||
|
||
export default async function(fastify: FastifyInstance) { | ||
fastify.get('/', async function(request: FastifyRequest, reply: FastifyReply) { | ||
return { message: 'Hello API' }; | ||
}); | ||
} |
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