Repository navigation
Expand file tree
/
Copy pathapp.js
More file actions
55 lines (49 loc) · 1.58 KB
/
Copy pathapp.js
File metadata and controls
55 lines (49 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import path from 'node:path'
import AutoLoad from '@fastify/autoload'
import fastifyCors from '@fastify/cors'
import { fileURLToPath } from 'node:url'
import fastifyStatic from '@fastify/static'
import fastifySwagger from '@fastify/swagger'
import fastifySwaggerUi from '@fastify/swagger-ui'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
// Pass --options via CLI arguments in command to enable these options.
export const options = {}
export default async function (fastify, opts) {
// Register before routes so public responses, including errors, support CORS.
fastify.register(fastifyCors, {
origin: '*',
methods: ['GET', 'HEAD', 'OPTIONS'],
credentials: false
})
fastify.register(fastifyStatic, {
root: path.join(__dirname, 'public')
})
fastify.register(fastifySwagger, {
openapi: {
openapi: '3.0.0',
info: {
title: 'The Report of the Week',
description: 'API for reports from The Report of the Week'
}
}
})
fastify.register(fastifySwaggerUi, {
exposeRoute: true,
routePrefix: '/docs'
})
// Do not touch the following lines
// This loads all plugins defined in plugins
// those should be support plugins that are reused
// through your application
fastify.register(AutoLoad, {
dir: path.join(__dirname, 'plugins'),
options: Object.assign({}, opts)
})
// This loads all plugins defined in routes
// define your routes in one of these
fastify.register(AutoLoad, {
dir: path.join(__dirname, 'routes'),
options: Object.assign({}, opts)
})
}