app.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. "use strict";
  2. const path = require("path");
  3. const AutoLoad = require("@fastify/autoload");
  4. const cors = require("@fastify/cors");
  5. const fstatic = require("@fastify/static");
  6. // Pass --options via CLI arguments in command to enable these options.
  7. module.exports.options = {};
  8. module.exports = async function (fastify, opts) {
  9. // Place here your custom code!
  10. fastify.register(fstatic, {
  11. root: path.join(__dirname, "lib"),
  12. prefix: "/lib/",
  13. setHeaders: (res, path, stat) => {
  14. res.setHeader("Cross-Origin-Embedder-Policy", "require-corp");
  15. },
  16. });
  17. fastify.register(cors, {
  18. // put your options here
  19. });
  20. // Do not touch the following lines
  21. // This loads all plugins defined in plugins
  22. // those should be support plugins that are reused
  23. // through your application
  24. fastify.register(AutoLoad, {
  25. dir: path.join(__dirname, "plugins"),
  26. options: Object.assign({}, opts),
  27. });
  28. // This loads all plugins defined in routes
  29. // define your routes in one of these
  30. fastify.register(AutoLoad, {
  31. dir: path.join(__dirname, "routes"),
  32. options: Object.assign({}, opts),
  33. });
  34. };