0

I want to achieve the following:

/login <- login page (static dir); after success it navigates to /app
/app <-redirects to either /app/board or to /app/calendar according to some req.session.param
/app/board <- app1 (static dir)
/app/calendar <- app2 (static dir)

The problem is when I do this:

webServer.use("/login", (req, res, next) => {
  if (req.session.isLogged) {
    res.redirect("/app");
  } else {
    next();
  }
});
webServer.use("/login", express.static("dist/auth"));
webServer.use("/app/board", (req, res, next) => {
  if (!req.session.isLogged) {
    res.redirect("/login");
  } else {
    if (req.session.application === CALENDAR) {
      res.redirect("/app/calendar");
    } else {
      next();
    }
  }
});
webServer.use("/app/board", express.static("dist/board"));
webServer.use("/app", (req, res, next) => {
  if (!req.session.isLogged) {
    res.redirect("/login");
  } else {
    if (req.session.application === CALENDAR) {
      res.redirect("/app/calendar");
    } else {
      res.redirect("/app/board");
    }
  }
});

I get some content from the expected /app/board but nothing else much except Refused to execute script from 'https://localhost:1337/app/board/' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

I searched for answers, but none worked (including using __dirname);

Funny enough when I mount either app to /app instead of to the nested /app/something the problem goes away. This leads me to the thought that it is somehow nesting-related and has something to do with the middle-wares I specify.

I am new to express, what am I missing?

fmi21
  • 485
  • 3
  • 15
  • Show us your client side code. It looks from the error like you're setting an HTML url to the src of a script tag. – Jared Smith Sep 14 '20 at 17:37
  • This is not an issue of express, but the error happens at client side. How is the request done on the client side? Also check the result of this request in the Network inspector – derpirscher Sep 14 '20 at 17:37
  • at the problematic /app/board/ should(and does)get served the following index: ... App ... – fmi21 Sep 14 '20 at 18:23
  • what I've missed are some external scripts - nothing interesting. the app itself however uses fetches extensivly. they are pretty similar: fetch("/app/board/someEndpoint")... someEndpoint is defined as get/post/something endpoint in the app.js file – fmi21 Sep 14 '20 at 18:24
  • Well from the error it seems, at least one of the scripts you are referencing in your html does not return with contentype `application/javascript` but with `text/html`. Check all script requests for correct response headers – derpirscher Sep 14 '20 at 19:02
  • Does this answer your question? [Refused to execute script, strict MIME type checking is enabled?](https://stackoverflow.com/questions/40574159/refused-to-execute-script-strict-mime-type-checking-is-enabled) – derpirscher Sep 14 '20 at 19:04
  • It unfortunately does not. The problem goes away when I mount either app to /app instead to /app/something so i think it has something to do with the nesting of static dir middlewares. – fmi21 Sep 15 '20 at 06:04

0 Answers0