Git Product home page Git Product logo

Comments (5)

ebebbington avatar ebebbington commented on June 15, 2024

As before request middleware is called without a response, this middleware will have to be after request middleware, which is a problem, because essentially none of the drash logic should need to run as when the request hits the web server, this middleware is going to return a response very early. for example:

How it would work now

  1. Drash gets a request
  2. runs all the logic around if request is for a resource etc
  3. runs the after request middleware

How it should work

  1. Drash gets request
  2. calls before request middleware, passing in response object
  3. this middleware runs, checks if request is for a static asset
  4. if it is, sends the response the client
  5. drash doesnt need to run any other logic, the middleware handles it all in this scenario

from deno-drash-middleware.

ebebbington avatar ebebbington commented on June 15, 2024

I understand that the response param in the middleware being a way to tell us if the request is before or ater, but maybe we should add an extra param instead so the response is always passed in

type MiddlewareFunction = (request: ..., response: ..., type: "before" | "after") => void

from deno-drash-middleware.

crookse avatar crookse commented on June 15, 2024

we could add an extra param so the response is always passed in, but i can't remember why we didn't do that

from deno-drash-middleware.

crookse avatar crookse commented on June 15, 2024

As before request middleware is called without a response, this middleware will have to be after request middleware, which is a problem, because essentially none of the drash logic should need to run as when the request hits the web server, this middleware is going to return a response very early. for example:

How it would work now

  1. Drash gets a request
  2. runs all the logic around if request is for a resource etc
  3. runs the after request middleware

How it should work

  1. Drash gets request
  2. calls before request middleware, passing in response object
  3. this middleware runs, checks if request is for a static asset
  4. if it is, sends the response the client
  5. drash doesnt need to run any other logic, the middleware handles it all in this scenario

you're right. damnit. so drash short-circuits all of the logic based on the request extension. if it has a .txt or .png or .jpg or whatever, then it knows the request is for a static asset. from there it goes "alrigh we don't have to execute the resource logic... just short-circuit this request and send the static asset". however, we don't have that kind of logic in middleware, so we'd need to add that logic... and it would possibly be a breaking change.

from deno-drash-middleware.

ebebbington avatar ebebbington commented on June 15, 2024

related PR is: drashland/drash#503

we'd have to use response.send() in this middleware to end the lifecycle

But we're in talks of removing the need for servestatic and using a resource inctead, so this comment might make no difference, but its here for reference regardless

from deno-drash-middleware.

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.