Giter VIP home page Giter VIP logo

Comments (3)

arctic-hen7 avatar arctic-hen7 commented on May 30, 2024

This is a really nice pattern, and one I've considered in the past as well, but the problem is that static content is hosted by frameworks in opaque, but accessible, URLs. To do this, you would have to add authentication middleware to block access to certain parts of the .perseus/static/ section of your site. While possible, this is hardly ergonomic as-is, but I'd be very willing to look at a library that would extend the Perseus servers to support this more ergonomically!

Do you have another way around this? I don't see that issue mentioned in your article (which was great by the way!).

from perseus.

eric-burel avatar eric-burel commented on May 30, 2024

Glad you liked it!
In the article I hide the logic in the isPaidUser function, however you are right that it's the hard part, for instance in Next.js the Edge middleware runtime is so limited that you can't establish a TCP connection to a db, so most often you can't check current user state reliably, unless you also use an HTTP-ready serverless database.
However, it's conceptually not much different from redirecting to for an A/B test, or towards the right language, the difference between those use cases only lies on how complicated is the logic that selects your "segment" and how many segments it creates. Either way you indeed need a dispatching middleware.
In an earlier version, this lead me to call this pattern the "unicorn architecture" or "rainbow rendering", as the magic is provided by adding a tiny proxy server, like the horn of the unicorn, and then you can render your site statically in as many colors as you want :)

from perseus.

arctic-hen7 avatar arctic-hen7 commented on May 30, 2024

Understood, right now Perseus doesn't have good support for middleware beyond customising the server used to host the app, but v0.5.x will include this, and I'd be happy to look at something then to make this approach more ergonomic at a framework-level, maybe even with first-class support --- this would certainly be possible by checking a JWT in a cookie or similar, although that limits the auth patterns this could be used with. This will probably be a plugin or otherwise separate crate, but we'll see how the final middleware API ends up looking! I'll leave this open for now.

from perseus.

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.