@xtaskjs/fastify-http
v1.0.21
Published
Fastify HTTP adapter for xtaskjs.
Readme
@xtaskjs/fastify-http
Fastify adapter package for xtaskjs HTTP applications.
This package is part of the xtaskjs project, hosted at xtaskjs.io.
Installation
npm install @xtaskjs/fastify-httpUsage
import fastify from "fastify";
import { CreateApplication, view } from "@xtaskjs/core";
import { FastifyAdapter } from "@xtaskjs/fastify-http";
const fastifyApp = fastify();
const app = await CreateApplication({
adapter: new FastifyAdapter(fastifyApp),
});
await app.listen({ port: 3000 });
// In a controller:
return view("home", { title: "Hello" });By default, FastifyAdapter uses:
views/as templates directorypublic/as static assets directory (/app.css,/images/logo.png, etc.).htmlas the template extension for filesystem templates
Custom Views/Public Paths
import path from "path";
const adapter = new FastifyAdapter(fastifyApp, {
templateEngine: {
viewsPath: path.join(process.cwd(), "resources/views"),
fileExtension: ".html",
},
staticFiles: {
publicPath: path.join(process.cwd(), "resources/public"),
urlPrefix: "/",
},
});You can also use the adapter shortcut in @xtaskjs/core:
await CreateApplication({
adapter: "fastify",
adapterInstance: fastifyApp,
});Resources
- Project site and documentation: xtaskjs.io
- npm package: @xtaskjs/express-http
- Source repository: xtaskjs/xtaskjs
