From 4d20a9a25e6ab836d057aa1a6e219300769e7637 Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Sat, 1 Mar 2025 02:37:24 -0600 Subject: [PATCH] Simplify Hono server and remove dynamic index generation --- app/src/index.ts | 122 +---------------------------------------------- 1 file changed, 2 insertions(+), 120 deletions(-) diff --git a/app/src/index.ts b/app/src/index.ts index cc5c773..14294f2 100644 --- a/app/src/index.ts +++ b/app/src/index.ts @@ -1,140 +1,22 @@ import { serve } from '@hono/node-server' import { Hono } from 'hono' import { serveStatic } from '@hono/node-server/serve-static' -import fs from 'node:fs' -import path from 'node:path' -import { fileURLToPath } from 'url' - -const __filename = fileURLToPath(import.meta.url) -const __dirname = path.dirname(__filename) const app = new Hono() -// Función para generar el HTML del índice -async function generateIndex() { - const templatesDir = path.join(__dirname, '../../templates') - const templates = fs.readdirSync(templatesDir) - .filter(file => fs.statSync(path.join(templatesDir, file)).isDirectory()) - - const html = ` - - - - - - Templates Directory - - - -

Available Templates

-
- ${templates.map(template => { - const templatePath = path.join(templatesDir, template) - const files = fs.readdirSync(templatePath) - return ` -
-

${template}

- -
- ` - }).join('')} -
- - - ` - return html -} - -// Middleware para logging app.use('*', async (c, next) => { - console.log(`Request path: ${c.req.path}`) await next() }) -// Servir archivos estáticos desde la carpeta templates app.use('/templates/*', serveStatic({ root: '../templates', rewriteRequestPath: (path) => { - console.log('Original path:', path) return path.replace('/templates/', '') } })) -// Ruta principal que muestra el índice -app.get('/', async (c) => { - return c.html(await generateIndex()) -}) - -// Ruta para generar el archivo index.html estático -app.get('/generate-static', async (c) => { - const html = await generateIndex() - const outputPath = path.join(__dirname, '../../docs/index.html') - - // Asegurarse de que el directorio docs existe - fs.mkdirSync(path.join(__dirname, '../../docs'), { recursive: true }) - - // Copiar la carpeta templates a docs - const templatesDir = path.join(__dirname, '../../templates') - const docsTemplatesDir = path.join(__dirname, '../../docs/templates') - fs.cpSync(templatesDir, docsTemplatesDir, { recursive: true }) - - // Guardar el index.html - fs.writeFileSync(outputPath, html) - return c.text('Static files generated in docs folder') +app.get('/', (c) => { + return c.text('Hello Hono!') }) serve({