1

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

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.