diff --git a/packages/sim-entrada-eventos/index.ts b/packages/sim-entrada-eventos/index.ts index 07717c6..cd2e6c7 100644 --- a/packages/sim-entrada-eventos/index.ts +++ b/packages/sim-entrada-eventos/index.ts @@ -7,6 +7,7 @@ import { env } from "#config/env/index.js" import { orderRoutes } from "#adapters/orderRoutes.http.js"; import { connectionsRoutes } from "#adapters/simconnectionsRoutes.js"; import { franceRoutes } from "#adapters/franceRoutes.http.js"; +import { spainRoutes } from "#adapters/spainRoutes.http.js"; const PORT = env.API_PORT const HOSTNAME = "0.0.0.0" diff --git a/packages/sim-entrada-eventos/infrastructure/franceRoutes.http.ts b/packages/sim-entrada-eventos/infrastructure/franceRoutes.http.ts index 3446ece..1412e7a 100644 --- a/packages/sim-entrada-eventos/infrastructure/franceRoutes.http.ts +++ b/packages/sim-entrada-eventos/infrastructure/franceRoutes.http.ts @@ -23,7 +23,7 @@ franceRoutes.use("", createProxyMiddleware({ const host = req.get('host'); const originalFullUrl = `${protocol}://${host}${req.originalUrl}`; const destinationFullUrl = `${FRANCE_URL}${proxyReq.path}`; - //console.log(`[Proxy Req]: ${req.method} ${req.url} -> ${proxyReq.path}`); + console.log(`[Proxy FR]: ${req.method} ${req.url} -> ${proxyReq.path}`); } } } diff --git a/packages/sim-entrada-eventos/infrastructure/portugalRoutes.http.ts b/packages/sim-entrada-eventos/infrastructure/portugalRoutes.http.ts new file mode 100644 index 0000000..48b151a --- /dev/null +++ b/packages/sim-entrada-eventos/infrastructure/portugalRoutes.http.ts @@ -0,0 +1,32 @@ +import { Router, Request } from "express" +import { ClientRequest, } from "http" +import { createProxyMiddleware } from "http-proxy-middleware" +import { env } from "#config/env/index.js" +import assert from "node:assert" + +const portugalRoutes = Router() + +const PORTUGAL_URL = env.NOS_CONSUMER_URL +assert.ok(PORTUGAL_URL, "No se ha definido una URL para el servicio consumidor de Francia") + +portugalRoutes.use("", createProxyMiddleware({ + target: PORTUGAL_URL, + changeOrigin: true, + pathRewrite: { + '^/spain/*': '/' + }, + + on: { + proxyReq: (proxyReq: ClientRequest, req: Request) => { + /* Debug de las peticiones */ + const protocol = req.protocol; + const host = req.get('host'); + const originalFullUrl = `${protocol}://${host}${req.originalUrl}`; + const destinationFullUrl = `${PORTUGAL_URL}${proxyReq.path}`; + console.log(`[Proxy PT]: ${req.method} ${req.url} -> ${proxyReq.path}`); + } + } +} +)) + +export { portugalRoutes } diff --git a/packages/sim-entrada-eventos/infrastructure/spainRoutes.http.ts b/packages/sim-entrada-eventos/infrastructure/spainRoutes.http.ts new file mode 100644 index 0000000..cf2512c --- /dev/null +++ b/packages/sim-entrada-eventos/infrastructure/spainRoutes.http.ts @@ -0,0 +1,33 @@ +import { Router, Request } from "express" +import { ClientRequest, } from "http" +import { createProxyMiddleware } from "http-proxy-middleware" +import { env } from "#config/env/index.js" +import assert from "node:assert" + +const spainRoutes = Router() + +const SPAIN_URL = env.ALAI_CONSUMER_URL +assert.ok(SPAIN_URL, "No se ha definido una URL para el servicio consumidor de Francia") + +spainRoutes.use("", createProxyMiddleware({ + target: SPAIN_URL, + changeOrigin: true, + pathRewrite: { + '^/spain/*': '/' + }, + + on: { + proxyReq: (proxyReq: ClientRequest, req: Request) => { + /* Debug de las peticiones */ + const protocol = req.protocol; + const host = req.get('host'); + const originalFullUrl = `${protocol}://${host}${req.originalUrl}`; + const destinationFullUrl = `${SPAIN_URL}${proxyReq.path}`; + console.log(`[Proxy ES]: ${req.method} ${req.url} -> ${proxyReq.path}`); + } + } +} +)) + +//orderRoutes.get("/:iccid/suspended-time",) +export { spainRoutes }