Fix para poder hacer ping

This commit is contained in:
2026-03-17 12:26:31 +01:00
parent 4d7e496574
commit d64d459648
6 changed files with 5969 additions and 12 deletions

View File

@@ -10,7 +10,7 @@ http:
type: json
data: |-
{
"card_id": "1234",
"card_id": "019cdd39-fc08-7417-b16d-a78794a24c01",
"override": false
}
auth: inherit

5926
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -10,14 +10,17 @@
"build": "tsc",
"build:esbuild": "esbuild --bundle src/main.ts --outdir=dist --platform=node --format=esm --packages=external",
"start": "node dist/main.js",
"migrate": "db-migrate -e .env -m ./deployment/database/migrations/ -t 99.0.0"
"migrate": "db-migrate -e .env -m ./deployment/database/migrations/ -t 99.0.0",
"build-start": "npm run build:esbuild && npm run start"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@types/cors": "^2.8.19",
"@types/express": "^5.0.6",
"@types/node": "^25.3.3",
"@types/pg": "^8.18.0",
"@usebruno/cli": "^3.1.3",
"esbuild": "0.27.3",
"ts-node": "^10.9.2",
"tsx": "^4.21.0",
@@ -26,6 +29,7 @@
"dependencies": {
"@sf-alvar/db-migrate": "^1.0.3",
"axios": "^1.13.6",
"cors": "^2.8.6",
"dotenv": "^17.3.1",
"express": "^5.2.1",
"pg": "^8.20.0",

View File

@@ -2,20 +2,21 @@ export function labelTemplate(code: string) {
return `
^XA
---------- SET LABEL SIZE (30mm x 30mm) ----------
^PW240
^LL240
---------- SET LABEL SIZE (40mm x 40mm) ----------
-- A 8pts/mm son 320 pts
^PW320
^LL320
---------- CENTERED QR CODE ----------
^FO50,20
^BQN,2,7
^FD${code}^FS
^BQN,2,10
^FDMA,${code}^FS
---------- BOTTOM CENTERED TEXT ----------
^FO0,195
^FO0,260
^A0N,25,25
^FB240,1,0,C
^FD${code}^FS
^FD${code}\\&^FS
^XZ
`

View File

@@ -10,7 +10,7 @@ export const errorHandler = (
res: Response,
next: NextFunction
) => {
console.error(err);
console.error("[x] Error en la peticion ", req, err);
res.status(err.status || 500).json({
message: err.message || 'Internal Server Error',
});

View File

@@ -1,8 +1,10 @@
import assert from 'assert';
import express, { Router, type Request, type Response } from 'express';
import express, { Router, type NextFunction, type Request, type Response } from 'express';
import { errorHandler } from './aplication/middleware.js';
import { env } from './config/env.config.js';
import cors from 'cors';
import type { ServerContext } from 'domain/ServerContext.js';
import { httpclient } from 'config/httpclient.config.js';
import { pgClient } from 'config/pgclient.config.js';
@@ -15,6 +17,22 @@ const HOSTNAME = env.HOST
assert(HOSTNAME != undefined)
// test
const requestLogger = (req: Request, res: Response, next: NextFunction) => {
const timestamp = new Date().toISOString();
const method = req.method;
const url = req.url;
const body = req.body;
// 'origin' comes from the request headers
const origin = req.get('origin') || 'No Origin (likely direct request/Server-side)';
console.log(`[${timestamp}] ${method} ${url} - Origin: ${origin} - Body: ${JSON.stringify(body)}`);
// Crucial: Call next() so the request doesn't hang!
next();
};
// Instancias de las dependencias
const serverContext: ServerContext = {
@@ -43,6 +61,7 @@ router.get("/health", (req: Request, res: Response) => {
})
router.post("/nfc/generate", ncfControllers.generateActivationTag())
router.head("/", (req, res) => res.status(200).send())
// Inicio de express
@@ -50,10 +69,17 @@ const app = express();
app.use(express.json());
app.use(cors({
origin: '*',
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
allowedHeaders: ['Content-Type', 'Authorization']
}))
app.use(requestLogger)
// Routes
app.use('/', router);
// Global error handler (should be after routes)
app.use(errorHandler);
app.listen(PORT, HOSTNAME, (n) => {