-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
47 lines (37 loc) · 1.17 KB
/
app.js
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
"use strict";
const path = require("node:path");
const AutoLoad = require("@fastify/autoload");
const cors = require("@fastify/cors");
const { initialize } = require("./initialize");
const config = require("./src/config");
// Pass --options via CLI arguments in command to enable these options.
const options = {
prefix: '/api',
};
/**
* @param {import('fastify').FastifyInstance} fastify
* @param {*} opts
*/
module.exports = async function (fastify, opts) {
console.log(`Running server with config: ${JSON.stringify(config)}`)
// Write cusrom code here
await initialize(config);
// 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, "src/plugins"),
options: Object.assign(options, opts),
});
fastify.register(cors, {
origin: "*",
})
// This loads all plugins defined in routes
// define your routes in one of these
fastify.register(AutoLoad, {
dir: path.join(__dirname, "src/routes"),
options: Object.assign(options, opts),
});
};
module.exports.options = options;