@sentzunhat/zacatl
Version:
A modular, high-performance TypeScript microservice framework for Node.js, featuring layered architecture, dependency injection, and robust validation for building scalable APIs and distributed systems.
30 lines • 955 B
JavaScript
import fastifyStatic from '@fastify/static';
export class FastifyPageAdapter {
server;
constructor(server) {
this.server = server;
}
registerStaticFiles(config) {
this.server.register(fastifyStatic, {
root: config.root,
...(config.prefix != null ? { prefix: config.prefix } : {}),
});
}
registerSpaFallback(apiPrefix, staticDir) {
this.server.setNotFoundHandler(async (request, reply) => {
if (request.raw.url != null && request.raw.url.startsWith(apiPrefix)) {
reply.status(404).send({
code: 404,
error: 'Not Found',
message: `Route ${request.method}:${request.url} not found`,
});
}
else {
reply.sendFile('index.html', staticDir);
}
});
}
async register() {
}
}
//# sourceMappingURL=fastify.js.map