first commit
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import fastifyStatic from '@fastify/static';
|
||||
import fastifyPlugin from 'fastify-plugin';
|
||||
|
||||
const projectRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..');
|
||||
const publicRoot = path.join(projectRoot, 'public');
|
||||
|
||||
async function staticPlugin(fastify, { config }) {
|
||||
await fastify.register(fastifyStatic, {
|
||||
root: config.imageRoot,
|
||||
prefix: '/media/',
|
||||
});
|
||||
await fastify.register(fastifyStatic, {
|
||||
root: publicRoot,
|
||||
prefix: '/',
|
||||
decorateReply: false,
|
||||
});
|
||||
|
||||
fastify.get('/login', async (_request, reply) => reply.sendFile('login.html', publicRoot));
|
||||
fastify.get('/', { preHandler: fastify.authenticatePage }, async (_request, reply) => (
|
||||
reply.sendFile('index.html', publicRoot)
|
||||
));
|
||||
fastify.get('/recipe/:id', { preHandler: fastify.authenticatePage }, async (_request, reply) => (
|
||||
reply.sendFile('recipe.html', publicRoot)
|
||||
));
|
||||
}
|
||||
|
||||
export default fastifyPlugin(staticPlugin, { name: 'static-pages' });
|
||||
|
||||
Reference in New Issue
Block a user