-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c5b2199
commit f6290e9
Showing
11 changed files
with
150 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"trifid": patch | ||
--- | ||
|
||
Install Helmet |
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,5 @@ | ||
--- | ||
"trifid": minor | ||
--- | ||
|
||
Allow to register plugins |
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,20 @@ | ||
// @ts-check | ||
|
||
/** | ||
* Register a Trifid plugin. | ||
* | ||
* @param {import('fastify').FastifyInstance} fastifyInstance Fastify instance | ||
* @param {import('../types/plugin.d.ts').TrifidPlugin} trifidPlugin Trifid plugin | ||
* @returns {Promise<void>} | ||
*/ | ||
export const registerPlugin = async (fastifyInstance, trifidPlugin) => { | ||
const { plugin, pluginOptions, routeOptions } = await trifidPlugin() | ||
|
||
if (plugin) { | ||
fastifyInstance.register(plugin, pluginOptions) | ||
} | ||
|
||
if (routeOptions) { | ||
fastifyInstance.route(routeOptions) | ||
} | ||
} |
This file was deleted.
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,28 @@ | ||
// @ts-check | ||
|
||
/** | ||
* Health plugin. | ||
* | ||
* @param {import('fastify').FastifyRequest} request Fastify request | ||
* @param {import('fastify').FastifyReply} reply Fastify reply | ||
* @returns {Promise<void>} | ||
*/ | ||
const healthPlugin = async (request, reply) => { | ||
request.log.debug('Some info about the current request') | ||
reply | ||
.code(200) | ||
.header('Content-Type', 'text/plain; charset=utf-8') | ||
.send('OK') | ||
} | ||
|
||
/** @type {import('../types/plugin.d.ts').TrifidPlugin}'} */ | ||
const trifidPlugin = async () => { | ||
return { | ||
routeOptions: { | ||
method: 'GET', | ||
url: '/healthz', | ||
handler: healthPlugin, | ||
}, | ||
} | ||
} | ||
export default trifidPlugin |
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,36 @@ | ||
// @ts-check | ||
import { dirname, join as pathJoin } from 'node:path' | ||
import { fileURLToPath } from 'node:url' | ||
|
||
import fastifyView from '@fastify/view' | ||
import Handlebars from 'handlebars' | ||
|
||
const trifidRootPath = dirname(dirname(fileURLToPath(import.meta.url))) | ||
|
||
/** @type {import('@fastify/view').default} */ | ||
const plugin = fastifyView | ||
|
||
/** @type {import('@fastify/view').FastifyViewOptions} */ | ||
const pluginOptions = { | ||
engine: { | ||
handlebars: Handlebars, | ||
}, | ||
root: pathJoin(trifidRootPath, 'views'), | ||
layout: './layouts/main', | ||
includeViewExtension: true, | ||
viewExt: 'hbs', | ||
propertyName: 'view', | ||
defaultContext: { | ||
dev: process.env.NODE_ENV === 'development', | ||
}, | ||
options: {}, | ||
} | ||
|
||
/** @type {import('../types/plugin.d.ts').TrifidPlugin} */ | ||
const trifidPlugin = async () => { | ||
return { | ||
plugin, | ||
pluginOptions, | ||
} | ||
} | ||
export default trifidPlugin |
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,6 @@ | ||
export type TrifidPluginResult = { | ||
plugin?: any; | ||
pluginOptions?: any; | ||
routeOptions?: import("fastify").RouteOptions; | ||
}; | ||
export type TrifidPlugin = () => Promise<TrifidPluginResult>; |
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 @@ | ||
Hello world! |