-
Notifications
You must be signed in to change notification settings - Fork 129
Add single page application support for Github pages #408
Comments
There's also the concept of To be clear, I think app authors should be using redirections along the lines of what @xiphiaz is describing (and some kind of route configuration file would be great for defining this, especially if a shared standard could be used across GitHub Pages and surge.sh), for the same reasons I described in the linked Twitter discussion (it matches the REST semantics the web has been designed for) - I just think these SPA platforms should work toward some kind of write-once-deploy-anywhere convergence (akin to the way the container backend world is converging on a single container standard right now). |
Also, something that would be fantastic: a way to specify a rule stating requests on catching routes should be directed to a page with whatever path was requested as part of the hash-fragment like a |
One thing I just realized (and mentioned on Twitter) is that what I'd really like for my static-resource-based design is routing to multiple pages, which could be handled nicely by making 200.html, rather than only working with one global file, to work for any request under that path (as opposed to index.html, which only works for the containing path exactly). I'd still want some mechanism to disable this in the aforementioned YAML config file (it's entirely possible I have a design that just has a page called "200.html" that isn't meant to have special behavior), but this would be a nice default for laying out app architectures for sites that Examples of sites that would reasonably have a 200.html that isn't meant to be served for all requests:
|
Building on that concept of having files for routes, I think it might also be useful to have some kind of file or sentinel value for setting up 301/302 redirects, possibly using a similar one-line value like the root I think the most sensible format for this value would be one space-separated line which works like CloudFlare's Page Rules (except evaluated path-relative to the file's location), where wildcards can be specified with As this would allow for developing single-page URL schemes that don't violate REST semantics, this would likely be the form I would use to structure my own apps, using a pattern like |
Also useful: an app-wide option for setting a redirect rule to direct requests for Though shorthands for these rules in the options would be nice, just keeping it simple with a |
Here's my overall thoughts on what a Static Access Rules Spec would look like (I'm going to go with "MUST" for all the rules below, since I think that's the model used by specs like the HTML Living Standard, where browsers are allowed to be divergent from the spec at the cost of officially being non-compliant with the relevant section). Unlike the HTML Living Spec (which addresses a many-headed beast that is far from any kind of "settled" functionality or uniform surface that can be targeted at once), I'm thinking this spec would be versioned (more like the DOM's "Levels"), with endpoints having compliance with specific versions of the spec (mod their own non-compliant shortcomings or extensions, which may be tracked by some kind of caniuse-type table). Level 0
Note that AFAIK no currently-shipping server supports all of Level 0 out-of-the-box (specifically, I'm pretty sure no server has directory listings off by default, nor do any redirect from index.html), but all the file servers I know do have configuration rules that can be applied to support Level 0 without any additional code to parse / translate Probably out-of-spec for non-orthogonality
So, CNAME has a number of issues here that not only keep me from wanting to specify it as Level 0, but also keep me from including it in Level 1, or even putting it in the spec at all:
Level 1
Level 2 (maybe)The On why I'm calling it
|
Just for reference, this is similar to the approach taken by Netlify, which offers both redirects and custom header support for static sites. Their redirect configuration is kept in
The last 2 are of note, because they allow:
The
So, its just paths followed by the custom headers. They also have support for other fancy features such as pre-rendering for SEO, and webhooks. Disclaimer: Have nothing to do with Netlify. And I wasted too much time looking for it in my HN comment history. HN Discussion |
I'm going to bed now, but I'll take a look at those tomorrow- my first reaction is that, while that looks neat and I do like the way it combines multiple mechanisms (rewriting, redirecting, custom-erroring, and forbidding/hiding) into one status-oriented syntax, that syntax also looks a little over-engineered (eg. the route params - I'm not sure if :slug turning into :story_id is a typo, but it'd be both simpler to implement and harder to mess up if done as $1/$2/$3/$4) and over-loaded (the query string being a separate space-separated field complicates arity checking when it could just be part of the match field) - not to mention I don't see how If I were to follow this pattern, I'd probably call it |
Okay, so I've had all this churning in the back of my mind as I went about my day (I've also had a great resurgence in appreciation for static-based app layouts, having this reliability as a baseline guarantee). Here are some notes from my current concept:
Open questions:
Anyway, this is rapidly getting too complex to continue to draft in this issue, so I'm going to continue this work in a repo (with probably the occasional pingback for progress to this issue) at https://github.com/stuartpb/s4-specs. |
Just remembered: one irking thing about the three-column model is that it doesn't allow a simple definition for "return the standard 403 or 404 page", so this might be cause for a "two-column rules use the default path" extension to the spec behavior. Again, I need to go to bed. |
@stuartpb This is a really great thread. FWIW - surge.sh already supports most things you have mentioned. Here is a list... Implicit Redirects & Clean URLs
Custom redirects using a
|
@sintaxi Interesting. Does Depending on what conventions and patterns I find with the other platforms, I might just go for standardizing on surge.sh's conventions and names. I'm still not wild about named route parameters, but if they're the only major difference between the existing ROUTER schema and what's strictly necessary I'll just standardize them (using the rules of https://github.com/pillarjs/path-to-regexp). Also, does your |
Also, re: defining HTTPS behavior in While I'm generally not the type of person to enforce a prescriptive best practice by gimping the things that are possible as part of a spec (which should aim almost exclusively to support any in-scope behaviors that were possible in its precedents), warelessly pasting in / writing "http://" at the beginning of your |
Vis. |
Note that |
Also to be in the spec: a note explaining that you have to use a route in the ROUTER file if you want your site to respond to requests for |
Also to note: while ALL of the codebase's files, by default, MUST be served normally (including those files that act as definitions), compliant compilers/generators/config-transpilers (both in implementations and in tooling) MUST take actions in their compiled files, if these files are not then re-introduced to the codebase, to respond to requests for those files as if those files did not exist (so eg. if pushing to your platform creates a Tooling that adds compiled files to a codebase (such as rendered template HTML files) MAY add rules in its generated ROUTER to hide any files (such as source templates), so long as these rules remain present and visible as part of the codebase after compilation. TODO: define "the codebase". |
Actually, I'm not sure about having the definition files exposed by default. Assuming there's a simple route to show/hide them (which I'm pretty set that there should be), both sides have the argument that it's easy enough to specify a rule in ROUTER to switch to the other. On the one hand, magic rules are a pain, and this makes introspection/openness a common part of the platform (the way so much of the web already is). It's irritating to have to pick off special-case rules defined by the spec just to make a server behave more predictably. On the other hand, exposing stuff like your routing rules, while you may or may not be exposing the files you may be hiding (and maybe you're only hiding certain files in one fashion and hadn't considered another way to access them, which is revealed by your ROUTER spec!), is a potential security hole, and "this is insecure by default, do this extra thing to secure it" is really a pretty bad scene. Also, I'm pretty sure there's precedent ie. in Apache hiding .htaccess - also there's a parallel to HTML here: (TODO: define interaction between So, actually, I think I'm going to walk back the assertion that definition files must me served as 200 by default, and instead say they must be served as 404 by default. End users may then wish to expose them with a Also the name I'm kicking around for a directory containing these files is |
It just occured to me the importance of adding the rules "Implementations in strict mode MUST NOT execute or interpret files outside this specification" and "Implementations MUST NOT write files to the code base in response to requests", basically as a way of officially saying "implementations MUST NOT turn into PHP". |
Any status about this? I find this a very hot feature, can't wait for it, I have demo pages which are broken because of lack of routing. Thanks! |
+1 |
Is there something to get routing with But if I go directly to the route: I get a 404 |
👍 |
3 similar comments
+1 |
+1 |
+1 |
When URL is not root, 404.html will redirect first to index.html, from where the app will start. https://github.com/rafrex/spa-github-pages track: isaacs/github#408
Mid 2019 and still no support for 200.html or similar. I think at the point, even just a "we're not going to do that" would be quite meaningful. |
I recommend using cloudflare CDN, where you can write up to 3 free rules, you should be able to setup a rule that works like a serverside redirect in htaccess, and all requests will silently pass through. If you had extra money you could whitelist all of your url slugs and send the rest to an error page. Handle this on your CDN provider. |
I found a cheap hack which "solves" the issue for me, without too much of a hassle: https://www.smashingmagazine.com/2016/08/sghpa-single-page-app-hack-github-pages/ It might be ok for your purposes? |
I solved with this.
|
Something new about it? |
Adding to this to force a notification to whomever is watching this thread. It's now 2021, this issue is nearly 6 years old, and we still don't have a good way to handle SPA on GitHub pages. The nasty |
Ideally GitHub might implement something like the
Netlify has a free hosting package, for anyone that has given up waiting for GitHub to support this |
Followed isaacs/github#408 and reached a solution to add 404 handler that redirects to / but has the path redirected as ? Credits: https://github.com/rafgraph/spa-github-pages
Not a universal solution, but since most github pages SPAs use My github repo serves the #!/bin/sh
npm run build
pages=foo bar baz/qux
for page in $pages
do
mkdir docs/$page
cp docs/index.html docs/$page/index.html
done Didn't try it with other SPA libs like You might need to only specify absolute paths in your |
As github pages does not support server side configuration (for example .htaccess files), it is impossible to get url rewriting to the index page working for a single page application.
Ideally, there should be a .gh-pages.yml or similar file in the repo root that has certain flags like
The above would be the equivalent of the following for nginx
The workaround is to use a hashbang like in angularjs html5 mode but this is fairly unsightly.
I think this feature is much wanted in the angular js community, and any other frontend javascript framework that supports the HTML5 History API.
The text was updated successfully, but these errors were encountered: