Skip to content

feat(backend): add proxy endpoint#85

Merged
mcollina merged 3 commits intoplatformatic:mainfrom
rozzilla:feat/backend/add-proxy-endpoint
Jun 11, 2025
Merged

feat(backend): add proxy endpoint#85
mcollina merged 3 commits intoplatformatic:mainfrom
rozzilla:feat/backend/add-proxy-endpoint

Conversation

@rozzilla
Copy link
Copy Markdown
Contributor

@rozzilla rozzilla commented Jun 9, 2025

Required for this PR in order to properly proxy requests to the right runtime service endpoints

@mcollina
Copy link
Copy Markdown
Member

mcollina commented Jun 9, 2025

How would it work?

@rozzilla
Copy link
Copy Markdown
Contributor Author

rozzilla commented Jun 9, 2025

How would it work?

@mcollina on the other PR I will dynamically override the URL used by scalar to do the service call. With this endpoint, I will proxy the requests to the right service runtime...

Signed-off-by: Roberto Bianchi <roberto.bianchi@spendesk.com>

fix

Signed-off-by: Roberto Bianchi <roberto.bianchi@spendesk.com>

fix(backend): properly use the wildcard and add tests

Signed-off-by: Roberto Bianchi <roberto.bianchi@spendesk.com>

update

Signed-off-by: Roberto Bianchi <roberto.bianchi@spendesk.com>

fix

Signed-off-by: Roberto Bianchi <roberto.bianchi@spendesk.com>

update

Signed-off-by: Roberto Bianchi <roberto.bianchi@spendesk.com>

update

Signed-off-by: Roberto Bianchi <roberto.bianchi@spendesk.com>

fix

Signed-off-by: Roberto Bianchi <roberto.bianchi@spendesk.com>
@rozzilla rozzilla force-pushed the feat/backend/add-proxy-endpoint branch from 8142093 to b074160 Compare June 10, 2025 20:49
Signed-off-by: Roberto Bianchi <roberto.bianchi@spendesk.com>
Signed-off-by: Roberto Bianchi <roberto.bianchi@spendesk.com>
@rozzilla rozzilla requested a review from mcollina June 11, 2025 09:12
const api = new RuntimeApiClient()

typedFastify.removeContentTypeParser(['application/json', 'text/*'])
typedFastify.addContentTypeParser('*', { parseAs: 'buffer' }, async (_request: unknown, body: unknown) => body)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would cause a bad warning if I recall.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any warning when starting the service:

[11:46:21.610] INFO (61130): Starting the service "backend"...
[11:46:22.571] INFO (backend/61130): Typescript compilation completed successfully.
[11:46:22.609] INFO (backend/61130): Server listening at http://127.0.0.1:53680
[11:46:22.610] INFO (61130): Started the service "backend"...
[11:46:22.610] INFO (61130): Starting the service "frontend"...
[11:46:22.690] ERROR (frontend/61130) <STDERR>: The CJS build of Vite's Node API is deprecated. See https://vite.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.
[11:46:22.724] INFO (61130): Started the service "frontend"...
[11:46:22.725] INFO (61130): Starting the service "composer"...
[11:46:23.025] INFO (composer/61130): start watching services
    services: [
      {
        "id": "backend",
        "openapi": {
          "url": "/documentation/json",
          "prefix": "/api"
        },
        "proxy": {
          "ws": {},
          "prefix": "/api"
        },
        "origin": "http://backend.plt.local"
      }
    ]
[11:46:23.060] INFO (composer/61130): Server listening at http://127.0.0.1:5042
[11:46:23.061] INFO (61130): Started the service "composer"...
[11:46:23.061] INFO (61130): Platformatic is now listening at http://127.0.0.1:5042

nor when I call the /proxy endpoint:

11:47:30.985] INFO (composer/61130): incoming request
    reqId: "2dd6917b-bb0a-4670-8975-5ee6f1ba3824"
    req: {
      "method": "GET",
      "url": "/api/proxy/61130/services/backend/runtimes/61130/health",
      "host": "localhost:5042",
      "remoteAddress": "127.0.0.1",
      "remotePort": 53730
    }
[11:47:30.986] INFO (composer/61130): fetching from remote server
    reqId: "2dd6917b-bb0a-4670-8975-5ee6f1ba3824"
    source: "/proxy/61130/services/backend/runtimes/61130/health"
[11:47:30.988] INFO (backend/61130): incoming request
    reqId: "006c2c74-36b9-4021-a1d9-35591673137d"
    req: {
      "method": "GET",
      "url": "/proxy/61130/services/backend/runtimes/61130/health",
      "host": "localhost:5042",
      "remoteAddress": "127.0.0.1",
      "remotePort": 53682
    }
[11:47:30.988] INFO (backend/61130): runtime request proxy
    serviceId: "backend"
    injectParams: {
      "method": "GET",
      "url": "/runtimes/61130/health",
      "headers": {
        "host": "backend.plt.local",
        "content-type": "application/json",
        "user-agent": "insomnia/10.2.0",
        "accept": "*/*",
        "x-forwarded-for": "127.0.0.1",
        "x-forwarded-host": "localhost:5042",
        "x-forwarded-proto": "http"
      },
      "query": {}
    }
[11:47:30.994] INFO (backend/61130): incoming request
    reqId: "74153ed0-828e-4f27-9d69-8a85285eb0d4"
    req: {
      "method": "GET",
      "url": "/runtimes/61130/health",
      "host": "localhost:5042",
      "remoteAddress": "127.0.0.1",
      "remotePort": 53731
    }
[11:47:30.999] INFO (backend/61130): request completed
    reqId: "74153ed0-828e-4f27-9d69-8a85285eb0d4"
    res: {
      "statusCode": 200
    }
    responseTime: 3.8473329842090607
[11:47:31.001] INFO (backend/61130): request completed
    reqId: "006c2c74-36b9-4021-a1d9-35591673137d"
    res: {
      "statusCode": 200
    }
    responseTime: 13.16687497496605
[11:47:31.002] INFO (composer/61130): response received
    reqId: "2dd6917b-bb0a-4670-8975-5ee6f1ba3824"
[11:47:31.004] INFO (composer/61130): request completed
    reqId: "2dd6917b-bb0a-4670-8975-5ee6f1ba3824"
    res: {
      "statusCode": 200
    }
    responseTime: 17.654415994882584

Copy link
Copy Markdown
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina merged commit e1e6424 into platformatic:main Jun 11, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants