app.js 1020 B

1234567891011121314151617181920212223242526272829303132333435
  1. 'use strict'
  2. const path = require('path')
  3. const AutoLoad = require('@fastify/autoload')
  4. const cors = require('@fastify/cors')
  5. // Pass --options via CLI arguments in command to enable these options.
  6. module.exports.options = {}
  7. module.exports = async function (fastify, opts) {
  8. await fastify.register(cors, {
  9. origin: true,
  10. allowedHeaders: '*',
  11. methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
  12. credentials: true
  13. })
  14. // Place here your custom code!
  15. // Do not touch the following lines
  16. // This loads all plugins defined in plugins
  17. // those should be support plugins that are reused
  18. // through your application
  19. fastify.register(AutoLoad, {
  20. dir: path.join(__dirname, 'plugins'),
  21. options: Object.assign({}, opts)
  22. })
  23. // This loads all plugins defined in routes
  24. // define your routes in one of these
  25. fastify.register(AutoLoad, {
  26. dir: path.join(__dirname, 'routes'),
  27. options: Object.assign({}, opts)
  28. })
  29. }