I am trying to use a proxy server I created using Express JS, along with Parcel as my bundler. However, the middleware for an endpoint does not seem to be used. The browser remains on my webpage despite having a different URL address with the proper endpoint. I am using the Parcel Watch command to bundle my entry files, which turns off Parcel's built-in dev server supposedly. I am not sure what is going on. I can provide more info if needed. Any help is much appreciated!
server.js
import express from "express";
import routerHome from "../js/home_router";
import tickerRouter from "../js/ticker_router";
const PORT = process.env.PORT || 3000;
const app = express();
app.use(express.static("dist"));
app.use(express.json());
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
next();
});
app.use("/", routerHome);
app.use("/ticker/:stock", tickerRouter);
app.listen(PORT, () => {
console.log("Proxy listening on port:", PORT);
});
ticker_router.js file:
import express from "express";
import path from "path";
const tickerRouter = express.Router();
tickerRouter.get("/", (req, res) => {
return res.sendFile(path.join("C:/Desktop/Ticqer2", "/dist/ticker.html"));
});
export default tickerRouter;
package.json:
{
"name": "ticqer2",
"version": "1.0.0",
"description": "",
"type": "module",
"scripts": {
"test": "",
"watch": "parcel watch src/home.html src/ticker.html" ,
"build": "parcel build --dist-dir public"
},
"author": "",
"license": "ISC",
"dependencies": {
"cnbc-market": "^3.0.0",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"http-proxy-middleware": "^2.0.6",
"nodemon": "^3.0.1",
"yahoo-finance2": "^2.8.1"
},
"devDependencies": {
"@parcel/transformer-sass": "^2.10.2",
"assert": "^2.1.0",
"browserify-zlib": "^0.2.0",
"buffer": "^6.0.3",
"events": "^3.3.0",
"https-browserify": "^1.0.0",
"os-browserify": "^0.3.0",
"parcel": "^2.10.2",
"process": "^0.11.10",
"stream-browserify": "^3.0.0",
"stream-http": "^3.2.0",
"url": "^0.11.3",
"util": "^0.12.5"
}
}