GithubHelp home page GithubHelp logo

express.js about reactql HOT 3 CLOSED

leebenson avatar leebenson commented on May 13, 2024
express.js

from reactql.

Comments (3)

leebenson avatar leebenson commented on May 13, 2024

You could edit kit/entry/server.js and re-write it with Express if you wanted, but I wouldn't recommend it.

Koa uses Promises as route handlers, which makes it possible to have middleware that 'awaits' further handlers, and thus interact with different parts of the request. We use that in the 'timer' as shown here:

  // It's useful to see how long a request takes to respond.  Add the
  // timing to a HTTP Response header
  .use(async (ctx, next) => {
    const start = ms.now();
    await next(); // <--- this 'yields' to the next handler, and resumes when it's done!
    const end = ms.parse(ms.since(start));
    const total = end.microseconds + (end.milliseconds * 1e3) + (end.seconds * 1e6);
    ctx.set('Response-Time', `${total / 1e3}ms`);
  });

AFAIK, you can't use that pattern in express, which makes it harder for a kit like ReactQL to implement convenience handlers like the one above.

I'd recommend you spend a few mins on http://koajs.com/ - it's basically 90% express, but using async functions as route handlers and the route 'context' being passed as an explicit parameter. It's the same Node HTTP server under the hood.

from reactql.

ablbol avatar ablbol commented on May 13, 2024

Good point. Thanks for letting me know.
Does Graphql support subscriptions with Koa? I really need it for my current project.

from reactql.

leebenson avatar leebenson commented on May 13, 2024

Yes, check out http://dev.apollodata.com/tools/graphql-subscriptions/

It hasn't been implemented in the ReactQL kit, but might be something that's added later.

from reactql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.