open-eats / OpenEats

:pizza: Self Hosted Recipe Management App :hamburger:
https://open-eats.github.io/
MIT License
670 stars 102 forks source link

404 error on refresh #42

Closed zingz0r closed 6 years ago

zingz0r commented 6 years ago

I'm getting 404 error when refreshing any page or entering link manually (for ex: @https://open-eats.github.io/recipe/1 ) So this is reproducable on https://open-eats.github.io.

Since I dont use nginx, don't know how to fix it, but in apache with this simple rewrite rule for public-ui directory you can use the links and the browser refresh.

<Directory "<path>/public-ui">
           RewriteEngine On
           RewriteBase /
           RewriteRule ^index\.html$ - [L]
           RewriteCond %{REQUEST_FILENAME} !-f
           RewriteCond %{REQUEST_FILENAME} !-d
           RewriteRule . /index.html [L]
           ... 
</Directory >

Update: Maybe something like this will do the trick (not tested)

server {
    listen 80;
    server_name localhost;

    location / {
        root /var/www/html/openeats-static/public-ui;
        try_files $uri $uri/ **=404**;
    }
    ...
RyanNoelk commented 6 years ago

The demo page that you are referring to is managed by github's infrastructure, so I don't have a way to add the rules. There is probably a way to get the demo site to work properly, but I haven't invested the time in doing so.

For the real site (IE, hosting your own) OpenEats already has the rules to redirect you. See: https://github.com/open-eats/openeats-nginx/blob/master/default.conf#L11

RyanNoelk commented 6 years ago

This is now fixed in the demo site. TLDR; Github will return a custom 404 page for when it can't find the URL. So we just need to make the 404 page the same as the index and everything works great. The index is only an entry point into the react app so there isn't any overhead.

See: https://github.com/open-eats/open-eats.github.io/commit/07984cef46c44643cb46dfb176b543ad5834dfd3