diff --git a/app/Dockerfile b/app/Dockerfile new file mode 100644 index 0000000..cd73115 --- /dev/null +++ b/app/Dockerfile @@ -0,0 +1,22 @@ +FROM node:20.9-slim + +WORKDIR /app + +# Crear la estructura de directorios +RUN mkdir -p public/templates + +# Copiar package.json y server.js +COPY ./app/package.json ./ +COPY ./app/server.js ./ + +# Copiar la carpeta templates +COPY ./templates ./public/templates/ + +# Instalar dependencias +RUN npm install express cors + +# Exponer el puerto +EXPOSE 4000 + +# Iniciar el servidor +CMD ["node", "server.js"] \ No newline at end of file diff --git a/app/package.json b/app/package.json new file mode 100644 index 0000000..9758476 --- /dev/null +++ b/app/package.json @@ -0,0 +1,9 @@ +{ + "name": "templates-server", + "version": "1.0.0", + "main": "server.js", + "dependencies": { + "express": "^4.18.2", + "cors": "^2.8.5" + } +} \ No newline at end of file diff --git a/app/server.js b/app/server.js new file mode 100644 index 0000000..4e516ce --- /dev/null +++ b/app/server.js @@ -0,0 +1,116 @@ +const express = require("express"); +const fs = require("fs").promises; +const path = require("path"); +const cors = require("cors"); + +const app = express(); +app.use(cors()); + +// Servir archivos estáticos desde la carpeta templates +app.use("/templates", express.static(path.join(__dirname, "public/templates"))); + +// Ruta para listar directorios en formato JSON +app.get("/api/templates", async (req, res) => { + try { + const templatesPath = path.join(__dirname, "public/templates"); + console.log("Buscando templates en:", templatesPath); // Para debug + + // Verificar si el directorio existe + try { + await fs.access(templatesPath); + } catch (e) { + console.error("El directorio no existe:", templatesPath); + return res.status(500).json({ error: "Directory not found" }); + } + + const dirs = await fs.readdir(templatesPath); + console.log("Directorios encontrados:", dirs); // Para debug + + const templates = await Promise.all( + dirs.map(async (dir) => { + const dirPath = path.join(templatesPath, dir); + const stat = await fs.stat(dirPath); + + if (stat.isDirectory()) { + const files = await fs.readdir(dirPath); + const filesInfo = await Promise.all( + files.map(async (file) => { + const filePath = path.join(dirPath, file); + const fileStat = await fs.stat(filePath); + return { + name: file, + path: `/templates/${dir}/${file}`, + size: fileStat.size, + modified: fileStat.mtime, + }; + }) + ); + + return { + name: dir, + path: `/templates/${dir}`, + files: filesInfo, + }; + } + return null; + }) + ); + + res.json({ + templates: templates.filter((t) => t !== null), + }); + } catch (error) { + console.error("Error:", error); // Para debug + res.status(500).json({ error: error.message }); + } +}); + +// Ruta para obtener información de un template específico +app.get("/api/templates/:template", async (req, res) => { + try { + const templatePath = path.join( + __dirname, + "public/templates", + req.params.template + ); + const files = await fs.readdir(templatePath); + + const filesInfo = await Promise.all( + files.map(async (file) => { + const filePath = path.join(templatePath, file); + const stat = await fs.stat(filePath); + return { + name: file, + path: `/templates/${req.params.template}/${file}`, + size: stat.size, + modified: stat.mtime, + }; + }) + ); + + res.json({ + name: req.params.template, + path: `/templates/${req.params.template}`, + files: filesInfo, + }); + } catch (error) { + res.status(500).json({ error: error.message }); + } +}); + +// Ruta para debug - muestra la estructura de directorios +app.get("/debug", (req, res) => { + const debugInfo = { + currentDir: __dirname, + publicTemplatesPath: path.join(__dirname, "public/templates"), + exists: fs.existsSync(path.join(__dirname, "public/templates")), + }; + res.json(debugInfo); +}); + +const PORT = 4000; +app.listen(PORT, () => { + console.log(`Server running on port ${PORT}`); + console.log("Directorio actual:", __dirname); + console.log("Ruta a templates:", path.join(__dirname, "public/templates")); +}); diff --git a/meta.json b/meta.json new file mode 100644 index 0000000..10434a7 --- /dev/null +++ b/meta.json @@ -0,0 +1,35 @@ +[ + { + "id": "pocketbase", + "name": "PocketBase", + "description": "Open Source backend in 1 file", + "version": "v0.22.4", + "logo": "pocketbase.svg", + "links": { + "github": "https://github.com/pocketbase/pocketbase", + "website": "https://pocketbase.io/", + "docs": "https://pocketbase.io/docs/" + }, + "tags": [ + "backend", + "database", + "api" + ] + }, + { + "id":"plausible", + "name":"Plausible", + "description":"Simple, reliable, and privacy-friendly web analytics", + "version":"v1.1.0", + "logo":"plausible.svg", + "links":{ + "github":"https://github.com/plausible/analytics", + "website":"https://plausible.io/", + "docs":"https://plausible.io/docs/" + }, + "tags":[ + "analytics", + "privacy" + ] + } +] diff --git a/templates/pocketbase/template.yml b/templates/pocketbase/template.yml index 52fff16..905d080 100644 --- a/templates/pocketbase/template.yml +++ b/templates/pocketbase/template.yml @@ -1,18 +1,3 @@ -metadata: - id: pocketbase - name: PocketBase - description: Open Source backend in 1 file - version: v0.22.4 - logo: pocketbase.svg - links: - github: https://github.com/pocketbase/pocketbase - website: https://pocketbase.io/ - docs: https://pocketbase.io/docs/ - tags: - - backend - - database - - api - variables: main_domain: ${randomDomain}