Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cors is hanging #307

Closed
dcsan opened this issue Nov 5, 2023 · 2 comments
Closed

cors is hanging #307

dcsan opened this issue Nov 5, 2023 · 2 comments

Comments

@dcsan
Copy link

dcsan commented Nov 5, 2023

I have a very simple app as below, but on adding the app.use(cors) it causes the app to hang indefinitely on all requestss
I disabled all other related config packages

as soon as I comment out app.use(cors); everything works again.

seems really simple - what could be wrong?

import cors from "cors";

import express, { Application } from "express";
// import compression from "compression";
// import cookieParser from "cookie-parser";
// import helmet from "helmet";
// import morgan from "morgan";

const ExpressConfig = (): Application => {
  const app = express();
  app.options("*", cors()); // include before other routes
  app.use(cors);

  app.use(express.json());

  return app;
};

export default ExpressConfig;

// server.ts

function setup() {
  const app = ExpressConfig();
  app.get("/", (_req: any, res) => {
    res.send("Hello World");
  });
app.listen(PORT, () => console.log("Server Running on Port " + PORT));
}

setup();
# package.json
  "dependencies": {
    "@types/morgan": "^1.9.7",
    "compression": "^1.7.4",
    "cookie-parser": "^1.4.6",
    "cors": "^2.8.5",
    "express": "^4.18.2",
    "helmet": "^6.0.1",
    "morgan": "^1.10.0"
  },

node -v
v18.16.1

@dcsan
Copy link
Author

dcsan commented Nov 5, 2023

and I just see pending request in the network tab

image

@dcsan
Copy link
Author

dcsan commented Nov 5, 2023

doh!

  app.use(cors); // wrong!
  app.use(cors() ); // right!

@dcsan dcsan closed this as completed Nov 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant