Forwarding ports from dns

Hello, i recently started working on APIs using NodeJS in combination with Express and MongoDB. I have the Node-Backend and MongoDB running locally on a Raspberry Pi. Now, for my custom version of Tic-tac-toe, i need to talk to the server … somehow. At the moment, i use DynDNS to have the port 3000 from my Raspberry Pi forwarded to my DNS domain, everything’s working so far. Now i want to have the Raspberry Pi somehow accessible from my Netlify website, not matter the DNS settings of the site, i just need the 3000 port accessible by the Netlify site. Redirects wouldn’t work, but i thought the “redirects” tag for the thread would be the best matching

Hey @DNAScanner

Have you tried configuring a rewrite proxy e.g.

_redirects version

/pi/*   https://example.com:8088/:splat   200

netlify.toml version

[[redirects]]
  from = "/pi/*"
  to = "https://example.com:8088/:splat"
  status = 200

I’ve tried the _redirects thing, but it doesnt seem to work. Accessing the site netlify site without using any subdirectory (just site.netlify.app) brings up the “Page not found” from netlify, just as expected but using site.netlify.app/api returns me a " This page isn’t working" (screenshot below). Talking to the server directly works perfectly fine, just the netlify redirect doesnt work

_redirects:
/api/* http://censored.net:3000/:splat 200

Error:

That isn’t a Netlify-produced error message in that screenshot.

Is it a problem with the redirect itself then? So it like doesnt allow a configuration like that or something?

A 200 redirect (a proxy as per previously linked documentation) simply returns whatever content the endpoint (in this case a raspberry pi in your home) returns. So, if the the endpoint returns a 500 Internal Server Error, a 400 Bad Request, 404 Not Found or 200 OK, this is then returned to whatever made the request in the first place.

So likely your Raspberry Pi has returned a 500 error that is then shown on your Netlify site.

Oh ok, but what does the :splat at the end do? And also, the things after the address itself test.netlify.app/directory1/test should be passed too, so it would connect to censored.net:3000/directory1/test

Using your redirect, given a request to the path /api/some/thing this then proxies through to http://example.com:3000/some/thing. If the path /api/search?q=something this proxies through to http://example.com:3000/search?q=something. That is what the wilcard * and :splat are doing. See Splats documentation.

Hi, @DNAScanner. It isn’t possible to change the port used when proxying at Netlify. Netlify assumes all HTTP connections will be on port 80 and all HTTPS connections will be on port 443.

Our support team can create a feature request for this but there is no way to modify the port when proxying at this time.

2 Likes

It would be really appreciated if you could create a feature request for that. Unless i couldn’t finish my game which is really sad, because I’ve been working so hard on it just for the online networking to not work

hi there DNAScanner, we can file a feature request, but i don’t think that any work will happen on this in the short term - it is likely that it may be several months, years, or it might never be implemented. Sorry, I wish I had better news for you.

Hi, @DNAScanner. I also wanted to mention that there is a workaround. You can always put a proxy or load balancer in front of that API so that it does respond on port 443.

Note, that isn’t something Netlify can do so you would need to use some other service. For example, you can put Cloudflare in front of your API. There instructions on this can be found here:

https://developers.cloudflare.com/fundamentals/get-started/reference/network-ports/

The API is still really using post 3000 behind the proxy. However, it will use port 443 via the proxy. You can then proxy the Netlify site to the Cloudflare proxy URL as it will be on port 443 there.

Again, that is a third-party workaround and not a “pure Netlify” solution. However, it might solve this more quickly than a feature request.

1 Like