| 15 | const { router, notFound } = createQwikCity({ render, qwikCityPlan }); |
| 16 | |
| 17 | const qwikPlugin: FastifyPluginAsync<FastifyQwikOptions> = async ( |
| 18 | fastify, |
| 19 | options, |
| 20 | ) => { |
| 21 | const { buildDir, distDir, assetsDir } = options; |
| 22 | |
| 23 | fastify.register(fastifyStatic, { |
| 24 | root: buildDir, |
| 25 | prefix: "/build", |
| 26 | immutable: true, |
| 27 | maxAge: "1y", |
| 28 | decorateReply: false, |
| 29 | }); |
| 30 | |
| 31 | fastify.register(fastifyStatic, { |
| 32 | root: assetsDir, |
| 33 | prefix: "/assets", |
| 34 | immutable: true, |
| 35 | maxAge: "1y", |
| 36 | }); |
| 37 | |
| 38 | fastify.register(fastifyStatic, { |
| 39 | root: distDir, |
| 40 | redirect: false, |
| 41 | decorateReply: false, |
| 42 | }); |
| 43 | |
| 44 | fastify.removeAllContentTypeParsers(); |
| 45 | |
| 46 | fastify.setNotFoundHandler(async (request, response) => { |
| 47 | await router(request.raw, response.raw, (err) => fastify.log.error(err)); |
| 48 | await notFound(request.raw, response.raw, (err) => fastify.log.error(err)); |
| 49 | }); |
| 50 | }; |
| 51 | |
| 52 | export default fastifyPlugin(qwikPlugin, { fastify: ">=4.0.0 <6.0.0" }); |