Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Is there a reason the documentation doesn't use the term "request handler" or something like that? If you define a callback without a next parameter, is it still considered a middleware?
    All the examples in the middleware callback function examples have the next parameter https://expressjs.com/en/5x/api.html#middleware-callback-function-examples
    James Pickard
    @euoia
    I think things would be clearer if handler functions were described as distinct from middleware
    The distinction being that middleware must call next, and the handler function must come last
    Nicolás Fantone
    @nfantone
    I don't know that there's an "official stance" on this, but I personally have used them interchangeably in the past
    James Pickard
    @euoia
    Ok, I will have a go at rewording it as part of this PR and perhaps we can discuss from there
    Nicolás Fantone
    @nfantone
    I mean, what would you call a handler that may call next on a given path, but not on others? I think it's rather subjective
    James Pickard
    @euoia
    Maybe I'd consider calling anything that sometimes calls next a middleware
    Nicolás Fantone
    @nfantone
    that might make sense, sure - in a more broad sense, I would call anything that takes in x and is expected to do something with it an "x handler"
    error handler, event handler, request handler, etc.
    James Pickard
    @euoia
    Maybe the docs should be clearer that a callback is expected to either 1) send a response, or 2) call next()?
    Would you say that's accurate?
    1 reply
    James Pickard
    @euoia
    James Pickard
    @euoia
    I created a pull request to update the documentation around async callbacks / middleware / request handlers
    James Pickard
    @euoia
    @nfantone I am just trying to understand the updated path-to-regexp documentation https://github.com/pillarjs/router/blob/27ca41b4aa9fce28948b96addbb8d8b67698dfa9/HISTORY.md
    Where it says "would match" or "would result" does that mean it used to but no longer does?
    1 reply
    In terms of impact on Express, for migrating Express from 4 to 5, I need to look at changes between n path-to-regexp 3.2.0 and 6.2.0, is that right (I'm basing that on the change to package.json in https://github.com/pillarjs/router/pull/102/files)
    1 reply
    James Pickard
    @euoia
    I guess I just need to copy those 4 bullet points, perhaps reword them to make them more Express-oriented
    James Pickard
    @euoia
    Ok @nfantone pull request created in the documentation repo expressjs/expressjs.com#1316
    James Pickard
    @euoia
    I reckon we should probably remove references to Express 3 in the v5 migration, I can't imagine it's very relevant to many people
    1 reply
    The app.router object, which was removed in Express 4, has made a comeback in Express 5. In the new version, this object is a just a reference to the base Express router, unlike in Express 3, where an app had to explicitly load it.
    James Pickard
    @euoia
    @nfantone @dougwilson are you aware of anything else I could help with?
    Nicolás Fantone
    @nfantone
    Nicolás Fantone
    @nfantone
    @euoia also reviewed expressjs/expressjs.com#1315
    James Pickard
    @euoia
    @iron2414mw did you figure it out?
    Norbert Varjasi
    @iron2414mw
    @euoia I did, took me sometime tho. The trick was to remove objects from the router stack, filtering them by path. Then it's gone, and I can even declare it again, if I want
    James Pickard
    @euoia
    ah right, interesting
    @crandmck are you still involved in Express documentation at all? We could use your help reviewing some documentation changes please
    James Pickard
    @euoia
    @dougwilson @nfantone the next milestone we're working towards, is that releasing Express v5 as a beta or releasing it as the main stable version (i.e. npm install express gives you v5)?
    2 replies
    James Pickard
    @euoia

    @nfantone did you get a resolution for your comment here https://github.com/expressjs/express/pull/4321#issuecomment-1003836216 ?

    I'm confused. Once pillarjs/router#102 is merged, a new (beta?) version of router would need to be cut and express would need to be updated again.

    Also changes in 1574925 were already part of #4752, which was put on hold and marked as "Draft" until the above takes place, but I see no mention of this.

    2 replies
    Tim Chen
    @momofarm
    hi, I'd like to find a google/facebook login implementation for expressjs, I found that Google and facebook has its own implementation, but also there is another lib call passportjs,
    Should I use passportjs or use google/fb own implementation?
    James Pickard
    @euoia
    Hi @momofarm - I don't have any experience on this but my understanding is that passportjs is fairly popular, so you should find good support for it. It's probably easier than integrating with the Google and Facebook implementations separately?
    Tim Chen
    @momofarm
    I'm thinking about using auth0, since I am a one man dev and don't have much budget on user management........
    gnubyte
    @gnubyte
    morning folks, is there a way to create an object in expressJS Middleware then access it down in a controller/route?
    James Pickard
    @euoia
    @gnubyte you can attach it to the request object in a middleware
    you can set arbitrary values on the request object which are then accessible to later routes and middleware
    A pattern I sometimes use is to attach a log object with info, debug, etc functions to the request object, that logs whatever you give it prefixed with a request ID
    Jim H
    @luckyl2000:matrix.org
    [m]
    don't have any experience in any sort of online/web development. I came up with an idea that I personally think is great in regard to the target audience it serves. I don't know if I should vividly share it on here but I would like to discuss the possibility of this online tool or service. I am looking to discuss this with someone familiar with the pharmaceutical world.
    can someone help or point me in the correct direction?
    James Pickard
    @euoia
    @luckyl2000:matrix.org it's always a tricky one when you have a good idea, of course you're not sure how much to share. Are you looking to discuss the technical feasibility of it with someone? I could possibly help you with that if you like
    efhan-the-unorthodox
    @efhan-the-unorthodox

    Hi I am working on an Express App with TypeScript
    I am trying to configure CSRF Tokens with the CSURF Library. I followed the documentation accordingly and I when I ran my app, there was no problem. However, upon trying to make a POST request, I get a 403 error saying ForbiddenError : invalid csrf token

    The following is the code in my main express app called app.ts

    import express, { request, Request, Response } from 'express'
    import 'dotenv/config'
    import passport from 'passport';
    import session from 'express-session';
    import clientController from './client/client';
    import cors from 'cors';
    import csurf from 'csurf';
    import cookieParser from 'cookie-parser';
    import bodyParser from 'body-parser';
    
    const app = express();
    app.use(cookieParser())
    app.use(bodyParser.urlencoded({ extended: true }))
    app.use(express.json())
    app.use(cors({
        credentials: true,
        origin: ['http://localhost:3000']
    }));
    
    const csrfMiddleware = csurf({ cookie: true })
    
    const port = process.env.PORT
    const sessionSecret = process.env.SESSION_SECRET
    
    app.use(session({
        secret: sessionSecret!.toString(),
        resave: true,
        saveUninitialized: false,
        cookie: {
            httpOnly: true
        }
    }))
    app.use(csrfMiddleware)
    
    app.use(passport.initialize());
    app.use(passport.session());
    
    passport.serializeUser((user: Object, done) => {
        console.log(user)
        done(null, user)
    })
    
    passport.deserializeUser((user: Object, done) => {
        done(null, user);
    })
    
    //Authentication route
    const authRoute = authController
    app.use('/auth', authRoute);

    I hope someone can assist me with this because I've spent a day or so trying to troubleshoot as to why I can't get csrf working

    Justice Lu
    @codingjlu
    The problem originated from the client side... how are you sending a request? You need to send the CSRF token with the request, probably including it with SSR (ejs or such).
    2 replies
    vincenzoml
    @vincenzoml
    Hello, question 0 for me about express.js: is there a simple way to map all the methods and fields of an objects to a route, with parameters where appropriate?
    1 reply
    I am thinking of writing something myself
    James Pickard
    @euoia
    @vincenzoml sure it's possible
    James Pickard
    @euoia
    @StephenLynx I can't speak for the Express team or on the matter you're discussing, but I can tell you that there's only a very small number of people working on Express at the moment, and most likely the website simply hasn't been updated for a long time
    Momoh Tyler
    @tylerjusfly
    is Express Open source?
    James Pickard
    @euoia
    Yep