BackendStack21 / fast-gateway

Fast-gateway is an easy to use Node.js API gateway framework built to handle large scale API traffic with great performance and scalability. Written with JavaScript, it is a framework for the masses!
MIT License
311 stars 35 forks source link

Unable to setup route for a Nuxt application. Guidance appreciated! #92

Closed safwanyp closed 4 months ago

safwanyp commented 4 months ago

Hello maintainers! Aplogies for posting an issue, but it seemed like the best place for now.

Anyways, I'm running a Nuxt 3 application at http://localhost:3000/reporting/finance. The gateway is running with express on port 8080 on localhost. Here's my index.js:

"use strict";

const http = require("http");
const helmet = require("helmet");
const express = require("express");
const gateway = require("fast-gateway");
const createHostnamesHook = require("fast-gateway/lib/hostnames-hook");

const expressApp = express().disable("x-powered-by").use(helmet());

/**
 * @type { Array<import("fast-gateway").Route> }
 */
const routes = [
  {
    pathRegex: "/reporting/finance",
    prefix: "/app",
    target: `http://localhost:3000/reporting/finance`,
  },
];
console.table(routes);

const hostname2prefixMap = [{ hostname: "app.dev.rew.ingka.com", prefix: "/app" }];
const hostnamesHook = createHostnamesHook(hostname2prefixMap);
const server = http.createServer((req, res) => {
  hostnamesHook(req, res, () => {
    return expressApp(req, res);
  });
});

gateway({
  server: expressApp,
  routes: routes,
});

const port = process.env.PORT || 8000;
server.listen(port, () => {
  console.log(`API Gateway listening on ${port} port!`);
});

With this setup, I am able to navigate to localhost:8080/app/reporting/finance and get a 200. But the 200 is only for the HTML document, and every other JS/CSS file returns a 404. Here's screenshots for the errors:
image

Screenshot 2024-05-07 at 19 04 11

I am not sure why this is happening, or how to solve this. Any help is appreciated!

safwanyp commented 4 months ago

Seems like it was a simple fix. The pathRegex was set to /reporting/finance. Once I changed it to /reporting/finance/* I was able to get the assets as needed.