@jb_fmanager/react setup for fastify
Include the routes and the utility package @jb_fmanager/node-utils
npm i @jb_fmanager/fastify @jb_fmanager/node-utils
yarn add @jb_fmanager/fastify @jb_fmanager/node-utils
root
Root folder for the frontend component
prefix
Must match the namespace provided to the manager, default is "api/fm".
maxUploadSize
If you want to override the value provided to the manager. Accepts bytes, ie 5242880 (5mb).
errorHandler
To handle errors your way, optional
const fastify = require("fastify")({ logger: true });
const path = require("path");
// including the package
require("@jb_fmanager/fastify")(fastify, {
root: "public",
prefix: "/api/fm",
errorHandler: undefined,
});
// registering static files
fastify.register((instance, opts, next) => {
instance.register(require("@fastify/static"), {
root: path.join(__dirname, "public"),
prefix: "/media",
});
next();
});
// including cors plugin
fastify.register(require("@fastify/cors"), {});
const start = async () => {
try {
await fastify.listen({ port: 4000 });
} catch (error) {
fastify.log.error(error);
}
};
start();