33 lines
772 B
TypeScript
33 lines
772 B
TypeScript
import fastify, { type FastifyServerOptions } from 'fastify'
|
|
import StatusError from './lib/status_error.ts'
|
|
import env from './env.ts'
|
|
import ErrorHandler from './handlers/error.ts'
|
|
import vitePlugin from './plugins/vite.ts'
|
|
import apiRoutes from './routes/api.ts'
|
|
import templatePublic from './templates/public.ts'
|
|
|
|
export default async (options: FastifyServerOptions) => {
|
|
const server = fastify(options)
|
|
|
|
server.setNotFoundHandler(() => {
|
|
throw new StatusError(404)
|
|
})
|
|
|
|
console.dir(env)
|
|
|
|
server.register(vitePlugin, {
|
|
mode: env.NODE_ENV,
|
|
createErrorHandler: ErrorHandler,
|
|
entries: {
|
|
public: {
|
|
path: '/',
|
|
template: templatePublic,
|
|
},
|
|
},
|
|
})
|
|
|
|
server.register(apiRoutes, { prefix: '/api' })
|
|
|
|
return server
|
|
}
|