Fix para poder hacer ping
This commit is contained in:
@@ -10,7 +10,7 @@ http:
|
|||||||
type: json
|
type: json
|
||||||
data: |-
|
data: |-
|
||||||
{
|
{
|
||||||
"card_id": "1234",
|
"card_id": "019cdd39-fc08-7417-b16d-a78794a24c01",
|
||||||
"override": false
|
"override": false
|
||||||
}
|
}
|
||||||
auth: inherit
|
auth: inherit
|
||||||
|
|||||||
5926
package-lock.json
generated
5926
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -10,14 +10,17 @@
|
|||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"build:esbuild": "esbuild --bundle src/main.ts --outdir=dist --platform=node --format=esm --packages=external",
|
"build:esbuild": "esbuild --bundle src/main.ts --outdir=dist --platform=node --format=esm --packages=external",
|
||||||
"start": "node dist/main.js",
|
"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": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/cors": "^2.8.19",
|
||||||
"@types/express": "^5.0.6",
|
"@types/express": "^5.0.6",
|
||||||
"@types/node": "^25.3.3",
|
"@types/node": "^25.3.3",
|
||||||
"@types/pg": "^8.18.0",
|
"@types/pg": "^8.18.0",
|
||||||
|
"@usebruno/cli": "^3.1.3",
|
||||||
"esbuild": "0.27.3",
|
"esbuild": "0.27.3",
|
||||||
"ts-node": "^10.9.2",
|
"ts-node": "^10.9.2",
|
||||||
"tsx": "^4.21.0",
|
"tsx": "^4.21.0",
|
||||||
@@ -26,6 +29,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sf-alvar/db-migrate": "^1.0.3",
|
"@sf-alvar/db-migrate": "^1.0.3",
|
||||||
"axios": "^1.13.6",
|
"axios": "^1.13.6",
|
||||||
|
"cors": "^2.8.6",
|
||||||
"dotenv": "^17.3.1",
|
"dotenv": "^17.3.1",
|
||||||
"express": "^5.2.1",
|
"express": "^5.2.1",
|
||||||
"pg": "^8.20.0",
|
"pg": "^8.20.0",
|
||||||
|
|||||||
@@ -2,20 +2,21 @@ export function labelTemplate(code: string) {
|
|||||||
return `
|
return `
|
||||||
^XA
|
^XA
|
||||||
|
|
||||||
---------- SET LABEL SIZE (30mm x 30mm) ----------
|
---------- SET LABEL SIZE (40mm x 40mm) ----------
|
||||||
^PW240
|
-- A 8pts/mm son 320 pts
|
||||||
^LL240
|
^PW320
|
||||||
|
^LL320
|
||||||
|
|
||||||
---------- CENTERED QR CODE ----------
|
---------- CENTERED QR CODE ----------
|
||||||
^FO50,20
|
^FO50,20
|
||||||
^BQN,2,7
|
^BQN,2,10
|
||||||
^FD${code}^FS
|
^FDMA,${code}^FS
|
||||||
|
|
||||||
---------- BOTTOM CENTERED TEXT ----------
|
---------- BOTTOM CENTERED TEXT ----------
|
||||||
^FO0,195
|
^FO0,260
|
||||||
^A0N,25,25
|
^A0N,25,25
|
||||||
^FB240,1,0,C
|
^FB240,1,0,C
|
||||||
^FD${code}^FS
|
^FD${code}\\&^FS
|
||||||
|
|
||||||
^XZ
|
^XZ
|
||||||
`
|
`
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ export const errorHandler = (
|
|||||||
res: Response,
|
res: Response,
|
||||||
next: NextFunction
|
next: NextFunction
|
||||||
) => {
|
) => {
|
||||||
console.error(err);
|
console.error("[x] Error en la peticion ", req, err);
|
||||||
res.status(err.status || 500).json({
|
res.status(err.status || 500).json({
|
||||||
message: err.message || 'Internal Server Error',
|
message: err.message || 'Internal Server Error',
|
||||||
});
|
});
|
||||||
|
|||||||
30
src/main.ts
30
src/main.ts
@@ -1,8 +1,10 @@
|
|||||||
import assert from 'assert';
|
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 { errorHandler } from './aplication/middleware.js';
|
||||||
import { env } from './config/env.config.js';
|
import { env } from './config/env.config.js';
|
||||||
|
|
||||||
|
import cors from 'cors';
|
||||||
|
|
||||||
import type { ServerContext } from 'domain/ServerContext.js';
|
import type { ServerContext } from 'domain/ServerContext.js';
|
||||||
import { httpclient } from 'config/httpclient.config.js';
|
import { httpclient } from 'config/httpclient.config.js';
|
||||||
import { pgClient } from 'config/pgclient.config.js';
|
import { pgClient } from 'config/pgclient.config.js';
|
||||||
@@ -15,6 +17,22 @@ const HOSTNAME = env.HOST
|
|||||||
|
|
||||||
assert(HOSTNAME != undefined)
|
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
|
// Instancias de las dependencias
|
||||||
|
|
||||||
const serverContext: ServerContext = {
|
const serverContext: ServerContext = {
|
||||||
@@ -43,6 +61,7 @@ router.get("/health", (req: Request, res: Response) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
router.post("/nfc/generate", ncfControllers.generateActivationTag())
|
router.post("/nfc/generate", ncfControllers.generateActivationTag())
|
||||||
|
router.head("/", (req, res) => res.status(200).send())
|
||||||
|
|
||||||
// Inicio de express
|
// Inicio de express
|
||||||
|
|
||||||
@@ -50,10 +69,17 @@ const app = express();
|
|||||||
|
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
|
|
||||||
|
app.use(cors({
|
||||||
|
origin: '*',
|
||||||
|
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
|
||||||
|
allowedHeaders: ['Content-Type', 'Authorization']
|
||||||
|
}))
|
||||||
|
|
||||||
|
app.use(requestLogger)
|
||||||
|
|
||||||
// Routes
|
// Routes
|
||||||
app.use('/', router);
|
app.use('/', router);
|
||||||
|
|
||||||
// Global error handler (should be after routes)
|
|
||||||
app.use(errorHandler);
|
app.use(errorHandler);
|
||||||
|
|
||||||
app.listen(PORT, HOSTNAME, (n) => {
|
app.listen(PORT, HOSTNAME, (n) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user