Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unexpected trailing slash behaviour with Firebase hosting

I'm seeing unexpected behaviour (at least as per me) with trailing slashes on Firebase Hosting. I expect Firebase to serve URLs with a trailing slash (except for actual files present in the hosting directory). For this I set trailingSlash to true in firebase.json.

This resulted in:

example.com                     redirect to     example.com/index.html/
example.com/js/script.js        redirect to     example.com/js/script.js/
example.com/images/image.png    redirect to     example.com/images/image.png/

The expected behaviour would be:

example.com                     redirect to example.com/
example.com/js/script.js        served as it is without any redirect
example.com/images/image.png    served as it is without any redirect

The addition of trailing slash to actual file URLs makes the browser/server think script.js is a directory instead of file and results in a 404. The addition of index.html to the root simply isn't elegant.

Expecting cleanUrls to do the trick I set cleanUrls to true along with trailingSlash and immediately the site goes into an endless redirect loop and fails to load. How can I stop Firebase from adding "index.html" at the root and the trailing slash for the actual js or image assets?

Edit:

As requested by Frank here's the firebase.json I'm using:

{
    "firebase"          : "example",
    "public"            : "public",
    "cleanUrls"         : false,
    "trailingSlash"     : true,
    "ignore"            : [ "firebase.json", "**/.*", "**/node_modules/**" ],
    "rewrites": [{

        "source"        : "**",
        "destination"   : "/index.html"

    }],
    "headers": [{

        "source"    : "**/*.@(eot|otf|ttf|ttc|woff|font.css)",
        "headers"   : [{

            "key"   : "Access-Control-Allow-Origin",
            "value" : "*"
        }]

    }, {

        "source"    : "**/*.@(jpg|jpeg|gif|png)",
        "headers"   : [{
            "key"   : "Cache-Control",
            "value" : "max-age=600"
        }]

    }, {

        "source"    : "**/*.@(html|js)",
        "headers"   : [{
            "key"   : "Cache-Control",
            "value" : "max-age=300"
        }]

    }]
}

P.S.: I have tried setting both trailingSlash and cleanUrls to true and also tried setting these true/false individually.

like image 257
Vinny Avatar asked Jan 27 '16 17:01

Vinny


1 Answers

https://firebase.google.com/docs/hosting/full-config#trailingslash

When true, it will redirect URLs to add a trailing slash. When false it will redirect URLs to remove a trailing slash. When unspecified, trailing slashes are used only for directory index files (e.g. about/index.html).

Just do not add that option and it will only affect urls

like image 61
jake Avatar answered Oct 19 '22 00:10

jake