In my express.js app, I have two controllers set up for handling requests: /auth and /posts.
I've implemented token authorization to set the Authorization cookie, but I'm encountering an issue when making a request to /posts. The request goes through the authMiddleware, which is supposed to validate the cookie. However, it's unable to access the cookie because the 'cookie' property doesn't exist on request.header, even though I am sending cookies through.
Interestingly, everything works as expected when I make a request to the /auth route, where request.header.cookie is populated correctly.
The structure of both controllers is quite similar, with a path property and a constructor that initializes the routes:
class PostsController implements Controller {
public path = '/posts';
public router = express.Router();
constructor() {
this.initializeRoutes();
}
public initializeRoutes() {
// Routes not shown for brevity
}
class AuthenticationController implements Controller {
public path = '/auth';
public router = express.Router();
// Constructor and routes initialization omitted
The problem seems to be related to the route being accessed rather than the controllers themselves. I've tried bypassing the controllers altogether, but the issue remains unresolved, perplexingly tied to the specific route I'm requesting.
I'm striving to access the cookie property consistently across all routes, and I need assistance in resolving this predicament.