34 lines
987 B
TypeScript
34 lines
987 B
TypeScript
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 }
|