Single Page App + Amazon S3 + Amazon CloudFront + Prerender.io - how to set up?

后端 未结 5 1194
清歌不尽
清歌不尽 2021-02-07 09:15
  1. I have single page app built with Backbone.js.
  2. I host app (app consists of static files only) on Amazon S3.
  3. I use CloudFront as a Bucket CDN.
  4. Ap
5条回答
  •  悲&欢浪女
    2021-02-07 09:55

    I managed to do this by not using Prerender at all but creating AWS Lambda function that:

    • Requests the origin page from CloudFront (it actually is always the same index.html)
    • Map the lambda function via API Gateway catch-all proxy
    • Study the path and figure out what resource page should be about (in my case it is simply /user/{name}, so I only have to do one use-case
    • Make REST API request to get the dynamic data for the user
    • Regex replace the existing meta-fields with the dynamic ones
    • Return the new index-file with new metas

    Configure new origin (new lambda function) and behaviour (map /user/* requests to this new origin). Be sure to use "HTTPS only" Origin Protocol Policy for the origin, as API Gateway is only HTTPS, redirect here will cause the hostname to change.

    (If you by accident used the redirect, then you will need to Invalidate "/*" as due to some CloudFront bug the configuration change will not help ; I spent multiple hours debugging this last night)

提交回复
热议问题