Q:

NGNIX reverse proxy NodeJS subdomain returns domain

I've written a NodeJS application that uses express and the express-subdomain package with the domains: api.localhost and localhost.
I'm attempting to use NGINX as a reverse proxy to handle requests to the app but my subdomain is returning content for the full domain. I'm having issues figuring out what the issue is- any ideas?
It seemed to work as expected when I wasn't using NGINX and no HTTPS; but I would like both of these to have HTTPS without buying a wildcard certificate (for now I'm using certbot which I think requires a way to define different certificates for each domain)

My router.ts file for the NodeJS app:
import * as express from 'express';
import * as subdomain from 'express-subdomain'; // See subdomain package

import { UserRoutes } from './User';
import { AuthRoutes } from './Auth';

export class Router {
    static routeAPI(app) {
        const router = express.Router();

        router.use((req, res, next) => {
            res.header('Access-Control-Allow-Origin', '*');
            res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,PATCH');
            res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
            next();
        });

        AuthRoutes.route(router);
        UserRoutes.route(router);

        app.use(subdomain('api', router)); // App uses subdomain
    }
}

My api.localhost site config file:
server {
    listen 80;

    server_name api.localhost;

    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;

    server_name api.localhost;
    access_log /var/log/nginx/api.localhost.log;

    ssl_certificate /etc/letsencrypt/live/api.localhost/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/api.localhost/privkey.pem;

    ssl_stapling on;
    ssl_stapling_verify on;

    location / {
        proxy_pass http://localhost:8080;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

I have attempted to:

change proxy_pass to http://api.localhost:8080
hard code proxy_set_header Host to api.localhost
use $http_host instead of $host

Note: localhost is purely used as an example domain

A:

Seems like within my server.js static files were being declared before my routes, so those got hit first.

This says that web/dist is used when the webserver is at /:
this.app.use('', express.static('web/dist'));

Which was declared before my routes:
Router.routeAPI(this.app);

/** Catch errors */
this.app.use((req, res, next) => {
    res.status(404);

    return res.json('Howdy');
});

this.app.use((err, req, res, next) => {
    if (res.headersSent) {
        return next(err);
    }

    if (err instanceof Response) {
        return res.status(err.status).json(err.toJSON());
    }

    return res.status(500).json(err);
});

