Mohamed El Mahallawy
Mohamed El Mahallawy

Reputation: 13842

angularjs html5mode in production as static files

How can I use Amazon S3 servers to serve Angularjs as static files with html5Mode(true) ?

Been following this blog but got stuck on pushing to production

Upvotes: 1

Views: 253

Answers (1)

morloch
morloch

Reputation: 1861

Unfortunately (for the moment), it doesn't appear to be possible using native S3 tools. Instead, I've been faking URL rewrites by actually copying index.html to any path used by angular. Here's the script I'm using to automate the process (my folder structure is based on yeoman, hence the reason I'm using the app/ and dist/ folders)

rm -rf dist-html5mode
for ROUTE in $(grep when app/scripts/app.js | awk -F\' '{print $2}' | grep -v '^/$'); do
    echo $ROUTE
    mkdir -p dist-html5mode$(dirname $ROUTE)
    cp dist/index.html dist-html5mode$ROUTE
done

Now that you have a populated dist-html5mode/ folder, upload its contents to the root of your S3 bucket and make sure you set the metadata Content-Type to text/html.

Upvotes: 1

Related Questions