u/philtrondaboss

FastAPI not working remotely

EDIT: It was interference from RAS. Removing RAS solved the problem, but I still need to figure out a way to use both.

I am trying to create a fastapi/uvicorn server, but I can't access it remotely. I have already set the host to '0.0.0.0' and I've already allowed it through my firewall. It works absolutely fine when accessed from localhost, but all external requests, from lan and wan, time out. I am using Windows Server 2025.

run(
    app = 'API.app:app',
    host = '0.0.0.0',
    port = 8000,
    workers = (None if VERBOSE else 2),
    ssl_certfile = this.file('certificates/cert').path,
    ssl_keyfile = this.file('certificates/key').path,
    log_level = "critical"
)
class CustomMiddleware(BaseHTTPMiddleware):

    def _log(self,
        request: Request, 
        status: str
    ) -> None:
        
        params = parse_qs(request.url.query)

        for name in params:
            if 'password' in name:
                params[name] = '***'

        Log.INFO(f"""
 HOST  = {request.client.host}
 PATH  = {request.url.path}
PARAMS = {params}
METHOD = {request.method}
STATUS = {status}
""")
    
    async def dispatch(self, 
        request: Request, 
        call_next
    ):

        self._log(request, '...')

        # Process the request
        response = await call_next(request)

        # Add the allow-all-origins header directly to the response
        response.headers["Access-Control-Allow-Origin"] = "*"
        response.headers["Access-Control-Allow-Methods"] = "*"
        response.headers["Access-Control-Allow-Headers"] = "*"

        self._log(request, response.status_code)

        return response
    
    async def __call__(self, *args, **kwargs):
        try:
            await super().__call__(*args, **kwargs)
        except Exception as e:
            Log.FAIL(str(e))

app.add_middleware(CustomMiddleware)

EDIT: I just tried disabling firewall altogether and it still didn't work. It shouldn't be any port forwarding issue, though. The server is a DMZ host, and lan doesn't work. I even changed the port for all clients and server to 8100 and it still didn't work.

My browsers gave this info:

Localhost:

"timings": {
          "blocked": 0,
          "dns": 0,
          "connect": 0,
          "ssl": 5,
          "send": 0,
          "wait": 1211,
          "receive": 20
}

LAN Client:

"timings": {
          "blocked": 0,
          "dns": 1,
          "connect": 0,
          "ssl": 0,
          "send": 0,
          "wait": 0,
          "receive": 
}
reddit.com
u/philtrondaboss — 21 hours ago