@jb_fmanager/react setup for fastify
Installation
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
Options
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).
const fastify = require("fastify")({ logger: true });
const path = require("path");
// including the package
require("@jb_fmanager/fastify")(fastify, { prefix: "/api/fm" });
// 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();
Example use
const fastify = require("fastify")({ logger: true });
const path = require("path");
// including the package
require("@jb_fmanager/fastify")(fastify, { prefix: "/api/fm" });
// 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();