XWWitPark/witpark_server/app.js
2024-09-12 08:10:00 +08:00

80 lines
2.1 KiB
JavaScript

'use strict'
const path = require('node:path')
const AutoLoad = require('@fastify/autoload')
const fastifyStatic = require('@fastify/static')
const cors = require('@fastify/cors')
// const mysql = require('@fastify/mysql')
const session = require('@fastify/session')
// const fastifyRedis = require('@fastify/redis')
const fastifyJwt = require('@fastify/jwt')
// const Redis = require('ioredis')
// const client = new Redis({ host: '127.0.0.1', port: 6379 })
// Pass --options via CLI arguments in command to enable these options.
const options = {}
module.exports = async function (fastify, opts) {
// Place here your custom code!
// 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)
})
fastify.register(AutoLoad, {
dir: path.join(__dirname, 'routes', 'v1', 'api'),
options: Object.assign({prefix: '/v1'}, opts)
})
fastify.register(AutoLoad, {
dir: path.join(__dirname, 'routes', 'v1', 'api', 'user'),
options: Object.assign({prefix: '/v1/api'}, opts)
})
fastify.register(fastifyStatic, {
root: path.join(__dirname, 'public'),
prefix: '/static/'
})
fastify.register(cors, {
origin: true,
credentials: true,
})
fastify.register(require('@fastify/cookie'))
fastify.register(session, {
secret: '5AD3BF54-0048-B5F7-F320-1CDB43D60BF5',
cookie: {
secure: false,
maxAge: 50000,
},
})
fastify.register(fastifyJwt, {
secret: '5AD3BF54-0048-B5F7-F320-1CDB43D60BF5'
})
// fastify.register(mysql, {
// promise: true,
// connectionString: 'mysql://root:123qwe@127.0.0.1:3306/witpark'
// })
// fastify.register(fastifyRedis, { client, closeClient: true })
}
module.exports.options = options