Code Monkey home page Code Monkey logo

Comments (18)

kennethreitz avatar kennethreitz commented on May 13, 2024 2

@metakermit that's exactly the flow that's in place.

from responder.

kennethreitz avatar kennethreitz commented on May 13, 2024 1

I like that.

from responder.

kennethreitz avatar kennethreitz commented on May 13, 2024 1

I have a prototype available here: #72

from responder.

kennethreitz avatar kennethreitz commented on May 13, 2024 1

@metakermit off master, you can now run static from /, but that disables all other routes;

api = responder.API(static_route="/")

from responder.

kennethreitz avatar kennethreitz commented on May 13, 2024 1

v0.1.0 released, which includes this.

from responder.

kennethreitz avatar kennethreitz commented on May 13, 2024

running 'npm build' that is.

from responder.

metakermit avatar metakermit commented on May 13, 2024

OK, great! I'll see if I can cook up a nice working example with Parcel + React and then we can talk about an official buildpack / Dockerfile or something that would run npm install / npm run build if there's a package.json and therefore encode this standard 🙂.

from responder.

metakermit avatar metakermit commented on May 13, 2024

As a first baby step, I've made a very minimal React + Parcel example featuring:

  • ES6 modules
  • image importing
  • frontend routing (using React-Router)

To deploy it's enough to do npm install & npm run build which packages everything in a dist folder ready for serving.

Here's the code:

https://github.com/metakermit/responder-react

I haven't touched any Responder stuff so far, but I see that there are going to be some challenges:

  • it should be possible to serve static files on / instead of static/
  • / should serve index.html
  • all urls not found in Responder's own routes should be forwarded to index.html (which would be needed for frontend routing)

Starlette has options for some of these things, but I think they aren't all exposed in Responder.

As a side-note, I did solve some of these issues with Django & Whitenoise here, so I have some ideas for how these things could be solved. Not sure what the best approach would be in Responder architecture-wise.

from responder.

metakermit avatar metakermit commented on May 13, 2024

Wow, that's a great start. I'll continue working on this tonight and see if I can get the cli to build the frontend if it's there (e.g. a package.json is present) and copy whatever's in dist to the static folder.

from responder.

kennethreitz avatar kennethreitz commented on May 13, 2024

Now, off master, if you do this:

api.add_route("/", static=True)

static/index.html's content will be the response to /.

from responder.

kennethreitz avatar kennethreitz commented on May 13, 2024

Now, off master, if you have a static=True route, all routes will be forwarded to static index.html responder.

from responder.

kennethreitz avatar kennethreitz commented on May 13, 2024

this still leaves

it should be possible to serve static files on / instead of static/

but I think that's a small workaround, for now.

from responder.

metakermit avatar metakermit commented on May 13, 2024

@kennethreitz Perfect, that solves most of the SPA requirements, I think 🎉 I'll test it and if it works, we can later see if we want to have some order of precedence in the future, e.g. in the static=True mode:

  1. check responder routes first (e.g. for some /api/users/ endpoints etc.)
  2. if there aren't any, redirect everything to index.html to handle
  3. the frontend then checks its routing and is responsible for the 404 page etc.

from responder.

kennethreitz avatar kennethreitz commented on May 13, 2024

I don't know much about single-page web apps, but this will always result in a 200 response from the server, even if it appears as though it's 404.

from responder.

kennethreitz avatar kennethreitz commented on May 13, 2024

unless there's a specific 404 view defined

from responder.

kennethreitz avatar kennethreitz commented on May 13, 2024

cool, i'll ship it :shipit:

from responder.

metakermit avatar metakermit commented on May 13, 2024

Sure, I think that's fine. I think the way it's done is that if the frontend doesn't find its template, it renders a 404 page. Traditionally this is done by setting nginx to forward everything to index.html, but with Responder we don't need nginx 🙂

Awesome! 🚀

from responder.

metakermit avatar metakermit commented on May 13, 2024

Just an update that I've managed to update https://github.com/metakermit/responder-react to seamlessly deploy to Heroku with everything working as expected 🎉

It took some custom Parcel flags, a custom Heroku build step and an app.json that configures multiple buildpacks, but now you can simply hit that "Deploy to Heroku" button and you have a super smooth Responder + React SPA experience 🙂

from responder.

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.