Skip to content

Commit 07aaddc

Browse files
committed
Add meta.json and update server infrastructure for template management
1 parent 760676d commit 07aaddc

File tree

5 files changed

+182
-15
lines changed

5 files changed

+182
-15
lines changed

app/Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM node:20.9-slim
2+
3+
WORKDIR /app
4+
5+
# Crear la estructura de directorios
6+
RUN mkdir -p public/templates
7+
8+
# Copiar package.json y server.js
9+
COPY ./app/package.json ./
10+
COPY ./app/server.js ./
11+
12+
# Copiar la carpeta templates
13+
COPY ./templates ./public/templates/
14+
15+
# Instalar dependencias
16+
RUN npm install express cors
17+
18+
# Exponer el puerto
19+
EXPOSE 4000
20+
21+
# Iniciar el servidor
22+
CMD ["node", "server.js"]

app/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "templates-server",
3+
"version": "1.0.0",
4+
"main": "server.js",
5+
"dependencies": {
6+
"express": "^4.18.2",
7+
"cors": "^2.8.5"
8+
}
9+
}

app/server.js

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
const express = require("express");
2+
const fs = require("fs").promises;
3+
const path = require("path");
4+
const cors = require("cors");
5+
6+
const app = express();
7+
app.use(cors());
8+
9+
// Servir archivos estáticos desde la carpeta templates
10+
app.use("/templates", express.static(path.join(__dirname, "public/templates")));
11+
12+
// Ruta para listar directorios en formato JSON
13+
app.get("/api/templates", async (req, res) => {
14+
try {
15+
const templatesPath = path.join(__dirname, "public/templates");
16+
console.log("Buscando templates en:", templatesPath); // Para debug
17+
18+
// Verificar si el directorio existe
19+
try {
20+
await fs.access(templatesPath);
21+
} catch (e) {
22+
console.error("El directorio no existe:", templatesPath);
23+
return res.status(500).json({ error: "Directory not found" });
24+
}
25+
26+
const dirs = await fs.readdir(templatesPath);
27+
console.log("Directorios encontrados:", dirs); // Para debug
28+
29+
const templates = await Promise.all(
30+
dirs.map(async (dir) => {
31+
const dirPath = path.join(templatesPath, dir);
32+
const stat = await fs.stat(dirPath);
33+
34+
if (stat.isDirectory()) {
35+
const files = await fs.readdir(dirPath);
36+
const filesInfo = await Promise.all(
37+
files.map(async (file) => {
38+
const filePath = path.join(dirPath, file);
39+
const fileStat = await fs.stat(filePath);
40+
return {
41+
name: file,
42+
path: `/templates/${dir}/${file}`,
43+
size: fileStat.size,
44+
modified: fileStat.mtime,
45+
};
46+
})
47+
);
48+
49+
return {
50+
name: dir,
51+
path: `/templates/${dir}`,
52+
files: filesInfo,
53+
};
54+
}
55+
return null;
56+
})
57+
);
58+
59+
res.json({
60+
templates: templates.filter((t) => t !== null),
61+
});
62+
} catch (error) {
63+
console.error("Error:", error); // Para debug
64+
res.status(500).json({ error: error.message });
65+
}
66+
});
67+
68+
// Ruta para obtener información de un template específico
69+
app.get("/api/templates/:template", async (req, res) => {
70+
try {
71+
const templatePath = path.join(
72+
__dirname,
73+
"public/templates",
74+
req.params.template
75+
);
76+
const files = await fs.readdir(templatePath);
77+
78+
const filesInfo = await Promise.all(
79+
files.map(async (file) => {
80+
const filePath = path.join(templatePath, file);
81+
const stat = await fs.stat(filePath);
82+
return {
83+
name: file,
84+
path: `/templates/${req.params.template}/${file}`,
85+
size: stat.size,
86+
modified: stat.mtime,
87+
};
88+
})
89+
);
90+
91+
res.json({
92+
name: req.params.template,
93+
path: `/templates/${req.params.template}`,
94+
files: filesInfo,
95+
});
96+
} catch (error) {
97+
res.status(500).json({ error: error.message });
98+
}
99+
});
100+
101+
// Ruta para debug - muestra la estructura de directorios
102+
app.get("/debug", (req, res) => {
103+
const debugInfo = {
104+
currentDir: __dirname,
105+
publicTemplatesPath: path.join(__dirname, "public/templates"),
106+
exists: fs.existsSync(path.join(__dirname, "public/templates")),
107+
};
108+
res.json(debugInfo);
109+
});
110+
111+
const PORT = 4000;
112+
app.listen(PORT, () => {
113+
console.log(`Server running on port ${PORT}`);
114+
console.log("Directorio actual:", __dirname);
115+
console.log("Ruta a templates:", path.join(__dirname, "public/templates"));
116+
});

meta.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[
2+
{
3+
"id": "pocketbase",
4+
"name": "PocketBase",
5+
"description": "Open Source backend in 1 file",
6+
"version": "v0.22.4",
7+
"logo": "pocketbase.svg",
8+
"links": {
9+
"github": "https://github.com/pocketbase/pocketbase",
10+
"website": "https://pocketbase.io/",
11+
"docs": "https://pocketbase.io/docs/"
12+
},
13+
"tags": [
14+
"backend",
15+
"database",
16+
"api"
17+
]
18+
},
19+
{
20+
"id":"plausible",
21+
"name":"Plausible",
22+
"description":"Simple, reliable, and privacy-friendly web analytics",
23+
"version":"v1.1.0",
24+
"logo":"plausible.svg",
25+
"links":{
26+
"github":"https://github.com/plausible/analytics",
27+
"website":"https://plausible.io/",
28+
"docs":"https://plausible.io/docs/"
29+
},
30+
"tags":[
31+
"analytics",
32+
"privacy"
33+
]
34+
}
35+
]

templates/pocketbase/template.yml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,3 @@
1-
metadata:
2-
id: pocketbase
3-
name: PocketBase
4-
description: Open Source backend in 1 file
5-
version: v0.22.4
6-
logo: pocketbase.svg
7-
links:
8-
github: https://github.com/pocketbase/pocketbase
9-
website: https://pocketbase.io/
10-
docs: https://pocketbase.io/docs/
11-
tags:
12-
- backend
13-
- database
14-
- api
15-
161
variables:
172
main_domain: ${randomDomain}
183

0 commit comments

Comments
 (0)