Deploys Backbone interface on S3

I have one javascript (Backbone) frontend page running on S3 and I would like for several extensions to be redirected to the same index file. You usually do this with mod_rewrite in Apache, but in S3 there is no way to do this.

I tried to set the default error document for the same as the index document and it works on the surface, but if you check the status heading of the actual response, you will see that the page returns as 404. This is obviously not very good.

There is another solution, its ugly, but better than hacking the error document:

It turns out that you can create a copy of index.html and name it just like a subdirectory (minus the trailing slash), for example, if I clone index.html and name it “about”, and make sure that for the parameter Content-Type is set to text / html (on the metadata tab) all requests in / will return a new "about", which is a copy of index.html.

Obviously, this solution is not optimal and only works with the predefined goals of de-engineering, but the problem can be reduced if the clone step index.html is part of the build process for the interface. Using the Backbone-Boilerplate, I could write this task to do this.

Apart from these two hacked workarounds, I see no way to do this otherwise than resorting to hashbangs ..

Any suggestions would be greatly appreciated.


UPDATE:

S3 now (for some time actually) supports Index Documents , which solves this problem.

Also, if you use Route 53 to manage your DNS, you can set up an alias record pointing to your S3 bucket, so you don't need subdomain + cname anymore :)

+4
source share
2 answers

Unfortunately, as far as I know (and I use s3 sites quite a bit), you are right for the money. Failing 404 is a really bad idea, as you said, and so you have the following options:

  • Use a regular backend, not S3
  • Content-Type Bypass
  • Hashbangs

Sorry to be the bearer of bad news :)

For me, the fact that you cannot direct the domain root to S3 sites was a transaction breaker for some of my things. mod_rewrite type type scripts sound like another good example where it just doesn't work.

+1
source

Have you tried redirecting to hash? I'm not sure if this S3 feature was available when you asked this question, but I was able to fix the problem using these redirection rules in the static web hosting section of the folder properties.

 <RoutingRules> <RoutingRule> <Condition> <KeyPrefixEquals>topic/</KeyPrefixEquals> </Condition> <Redirect> <ReplaceKeyPrefixWith>#topic/</ReplaceKeyPrefixWith> </Redirect> </RoutingRule> </RoutingRules> 

The rest is processed in the Backbone.js application.

+1
source

Source: https://habr.com/ru/post/1396859/


All Articles