app.js 917 B

1234567891011121314151617181920212223242526272829303132333435
  1. 'use strict'
  2. const path = require('path');
  3. const AutoLoad = require('fastify-autoload');
  4. const CORS = require('fastify-cors');
  5. module.exports = function (fastify, opts, next) {
  6. fastify.register(CORS, {
  7. origin: 'http://localhost:3000',
  8. preflight: true,
  9. preflightContinue: true,
  10. credentials: true,
  11. methods: ['GET', 'PUT', 'PATCH', 'POST', 'DELETE'],
  12. })
  13. // Do not touch the following lines
  14. // This loads all plugins defined in plugins
  15. // those should be support plugins that are reused
  16. // through your application
  17. fastify.register(AutoLoad, {
  18. dir: path.join(__dirname, 'plugins'),
  19. options: Object.assign({}, opts)
  20. })
  21. // This loads all plugins defined in services
  22. // define your routes in one of these
  23. fastify.register(AutoLoad, {
  24. dir: path.join(__dirname, 'services'),
  25. options: Object.assign({}, opts)
  26. })
  27. // Make sure to call next when done
  28. next()
  29. }