Gateway para francia funciona
This commit is contained in:
7
.env
7
.env
@@ -30,3 +30,10 @@ PGPORT=5433
|
||||
|
||||
# Proxy
|
||||
CONNECTIONS_URL=https://sim-connections.savefamilygps.net
|
||||
|
||||
# Conexiones internas de servicios
|
||||
GATEWAY_URL=http://localhost:3000
|
||||
NOS_CONSUMER_URL=http://localhost:3001
|
||||
NOS_CONSUMER_PORT=3001
|
||||
OBJENIOUS_CONSUMER_URL=http://localhost:3002
|
||||
OBJENIOUS_CONSUMER_PORT=3002
|
||||
|
||||
21
docs/sim-api/France Suspended Time.bru
Normal file
21
docs/sim-api/France Suspended Time.bru
Normal file
@@ -0,0 +1,21 @@
|
||||
meta {
|
||||
name: France Suspended Time
|
||||
type: http
|
||||
seq: 15
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{baseurl}}/france/lines/{{iccid}}/suspended-time
|
||||
body: none
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
vars:pre-request {
|
||||
iccid: 8933201125065160331
|
||||
~baseurl: http://localhost:3002
|
||||
}
|
||||
|
||||
settings {
|
||||
encodeUrl: true
|
||||
timeout: 0
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
# claves de Objenious
|
||||
HOST=0.0.0.0
|
||||
PORT=3002
|
||||
|
||||
OBJ_PEM_PATH=./obj.pem
|
||||
OBJ_AUTHORIZATION=XOc7FtwXD8hUX2SFVX94XSty8wkOmChkwDNF09O_aIxPubMDdFUdCDCB4zpzSIxi8nOcTg7r_LM_nmd5qm7uLbksf_XArjI8iAyhjKz_2BAXPhmvKs4Fc9f3vv5LDfCVrPB9lP8P7rJ66_qnWs4jvhLQxSfn29m96hgXeCf8oySdIDUjN2q9Js3KAS5LL52Ri6ryvUeO1PvMhaPQMWRqoHIqTV1wPfPtiqQwcjUPmu5GeW164Kq1JLgV3KaGzfCZ9Qv9lbv30EJrukXxWuLCAhBS0kzrBXZoWvf2pb9uh3Am_93_dDxiIGQfIap9ZU_m8ZD1HPgvZOMCY6ZkxQconQ
|
||||
|
||||
@@ -4,7 +4,10 @@ import path from "node:path";
|
||||
loadEnvFile(path.join("../../.env")) // Global
|
||||
loadEnvFile(path.join("./.env")) // base
|
||||
|
||||
|
||||
export const env = {
|
||||
PORT: parseInt(process.env.OBJENIOUS_CONSUMER_PORT || "3002"),
|
||||
|
||||
ENVIRONMENT: process.env.ENVIORMENT,
|
||||
POSTGRES_USER: process.env.POSTGRES_USER,
|
||||
POSTGRES_PASSWORD: process.env.POSTGRES_PASSWORD,
|
||||
|
||||
@@ -13,6 +13,7 @@ import { PauseCancelTaskRepository } from "#adapters/PauseCancelTaskRepository.j
|
||||
import express from "express"
|
||||
import cors from "cors"
|
||||
import assert from "node:assert";
|
||||
import { env } from "#config/env/index.js"
|
||||
|
||||
async function startWorker() {
|
||||
const rmqClient = await startRMQClient()
|
||||
@@ -48,7 +49,8 @@ async function startWorker() {
|
||||
rmqClient.consume("sim.objenious", simRouter.route)
|
||||
|
||||
// Servidor express
|
||||
const port = process.env.PORT
|
||||
const port = env.PORT
|
||||
console.log("PUERTO OBJ ", port)
|
||||
const app = express()
|
||||
app.use(cors())
|
||||
app.use(express.json())
|
||||
|
||||
@@ -3,6 +3,7 @@ import path from "node:path";
|
||||
|
||||
|
||||
loadEnvFile(path.join("../../.env")) // Global
|
||||
//loadEnvFile(path.join("./.env")) // Global
|
||||
|
||||
export const env = {
|
||||
ENVIRONMENT: process.env.ENVIORMENT,
|
||||
@@ -22,5 +23,7 @@ export const env = {
|
||||
RABBITMQ_SECURE: process.env.RABBITMQ_SECURE,
|
||||
RABBITMQ_RETRY_INTERVAL: process.env.RABBITMQ_INTERVAL,
|
||||
RABBITMQ_VHOST: String(process.env.RABBITMQ_VHOST),
|
||||
CONNECTIONS_URL: String(process.env.CONNECTIONS_URL)
|
||||
CONNECTIONS_URL: String(process.env.CONNECTIONS_URL),
|
||||
OBJENIOUS_CONSUMER_URL: process.env.OBJENIOUS_CONSUMER_URL,
|
||||
NOS_CONSUMER_URL: process.env.NOS_CONSUMER_URL,
|
||||
};
|
||||
|
||||
@@ -6,6 +6,7 @@ import { rabbitmqEventBus } from '#config/eventBusConfig.js';
|
||||
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";
|
||||
|
||||
const PORT = env.API_PORT
|
||||
const HOSTNAME = "0.0.0.0"
|
||||
@@ -31,6 +32,9 @@ app.use("/orders", orderRoutes)
|
||||
|
||||
app.use("/docs", express.static(path.join(process.cwd(), '../../docs')))
|
||||
|
||||
// Rutas especificas para casos especiales como el tiempo de suspension de francia
|
||||
app.use("/france", franceRoutes)
|
||||
|
||||
app.get("/health", (req, res) => {
|
||||
res.status(200).json({ status: "ok" })
|
||||
})
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
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 franceRoutes = Router()
|
||||
|
||||
const FRANCE_URL = env.OBJENIOUS_CONSUMER_URL
|
||||
assert.ok(FRANCE_URL, "No se ha definido una URL para el servicio consumidor de Francia")
|
||||
|
||||
franceRoutes.use("", createProxyMiddleware({
|
||||
target: FRANCE_URL,
|
||||
changeOrigin: true,
|
||||
pathRewrite: {
|
||||
'^/france/*': '/'
|
||||
},
|
||||
|
||||
on: {
|
||||
proxyReq: (proxyReq: ClientRequest, req: Request) => {
|
||||
const protocol = req.protocol;
|
||||
const host = req.get('host');
|
||||
const originalFullUrl = `${protocol}://${host}${req.originalUrl}`;
|
||||
const destinationFullUrl = `${FRANCE_URL}${proxyReq.path}`;
|
||||
|
||||
console.log('──────────────────────────────────────────────────');
|
||||
console.log(`[PROXY_DEBUG]`);
|
||||
console.log(` ENTRADA: ${originalFullUrl}`);
|
||||
console.log(` MÉTODO : ${req.method}`);
|
||||
console.log(` DESTINO: ${destinationFullUrl}`);
|
||||
console.log('──────────────────────────────────────────────────');
|
||||
|
||||
console.log(`[Proxy Req]: ${req.method} ${req.url} -> ${proxyReq.path}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
))
|
||||
|
||||
|
||||
//orderRoutes.get("/:iccid/suspended-time",)
|
||||
export { franceRoutes }
|
||||
Reference in New Issue
Block a user