[RFC] Server-side Website #43
Replies: 8 comments 41 replies
-
First, this is HUGE ! This is a major hassle for classic fullstack websites when running in Lambda.
I would go with the 5th option : Fullstack Website 😅 What I dislike about
Is it Cloudfront edge cache where an invalidation will clear everything up, or is it a cache-control header added to the assets ? If it's the later, would it be possible to configure which paths are cached and which are not ? If using something like webpack, you can add a hash to assets but if your are building something simple, then you wmight not version your assets and some third parties might not allow that at all (for example, Symfony assets provided by third-party bundles are not versionned and I'm not sure you can do it). Something like constructs:
website:
# ...
assets:
'/bundles/*':
path: public/bundles/
cache: false # this disables cache-control headers or sets it to 0
'/build/*': public/build/ # this uses the default cache behaviour Let me know what you think. |
Beta Was this translation helpful? Give feedback.
-
tested it yesterday with symfony/demo and it worked for the most part. There are still some hiccups which are blocking it even on a simple app like the demo :
Otherwise, it seems to work well. I'll to test this with a Server-Side rendered Vue app I have and see how it turns out. |
Beta Was this translation helpful? Give feedback.
-
Quick question, how can I test it on a project? It is not merged yet, so I'm not sure what should I do to install this package version. |
Beta Was this translation helpful? Give feedback.
-
Thank you for this! This works great. But how can we correctly handle different stages?
It could be nice to allow a main stage = main domain ( |
Beta Was this translation helpful? Give feedback.
-
Hey all, a quick update. I've been reading about HSTS (which is nothing new) and TIL: there are now lists maintained by Chrome and Firefox of "HTTPS-only" websites (https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security#preloading_strict_transport_security). That allows a website to be 100% HTTPS-only, and still work in all browsers. That makes me think that we may want to consider hosting websites without CloudFront at all? CloudFront is still useful to host everything behind a single domain and benefit from CDN caching. But it takes a while to setup/deploy. Maybe we will want a simple-website construct? I'm just throwing the idea out there. CloudFront may not be absolutely required anymore. |
Beta Was this translation helpful? Give feedback.
-
How would I handle a case where I want to provide public access to user uploaded files? Is there any way to map a path, /uploads, to a storage S3 bucket? |
Beta Was this translation helpful? Give feedback.
-
Would it be possible to create a new version of this construct or update this to use the Lambda Function Url instead of API Gateway? Lambda Function Url seems like the perfect companion for this construct together with something like Laravel |
Beta Was this translation helpful? Give feedback.
-
Hello, With the new extensions, is it possible to add new origins for website construct? I have tested this: `website:
` Getting this error:
Is my .yml simply wrong or is there something I am missing? Looking to create Cloudfront distribution for user uploaded files. Do I need to create completely new distribution for this? Thank you. |
Beta Was this translation helpful? Give feedback.
-
The goal of this discussion is to get feedback on a "Server-side Website" component.
By Server-side website, I mean a website where the HTML is rendered on the server. This is usually done with backend frameworks like Laravel/Symfony (PHP), Ruby on Rails, Django/Flask (Python), Express (Node), etc.
To build a SPA or static website, use the Static Website construct instead.
Name
Possible names for the constructs could be:
Any opinion? IMO "server-side" (or "server") goes nicely with "static website".
Use case
Deploying websites served via code on Lambda. E.g. websites built with Laravel/Symfony (PHP with Bref), Django/Flask (Python with the wsgi plugin), Express/... (Node), etc.
Quick start
The example above will set up CloudFront to serve both:
https://<domain>/*
-> the website through API Gateway + Lambdahttps://<domain>/css/*
andhttps://<domain>/js/*
->assets through S3On
serverless deploy
, assets are uploaded to S3 and the CloudFront cache is invalidated.Note: this component takes about 5 minutes to deploy the first time.
How it works
Why CloudFront?
API Gateway's HTTP APIs do not support HTTP. For a website, this is problematic because it means someone typing
website.com
in a browser will get a blank page: API Gateway will not even redirect this to HTTPS.We need CloudFront to redirect HTTP -> HTTPS.
CloudFront also provides caching of assets (just like for static websites, as well as routing URLs based on prefixes:
CloudFront configuration
CloudFront is configured to cache static assets by default, but not cache dynamic content by default.
CloudFront is configured to forward all headers, cookies, and query strings to the backend running on Lambda.
Using CloudFront Functions, the
X-Forwarded-Host
header will also be automatically populated to resolve a shortcoming of CloudFront + API Gateway. Code running on Lambda will be able to access the originalHost
header via thisX-Forwarded-Host
header.Commands
serverless deploy
deploys everything configured inserverless.yml
and uploads assets.It is possible to skip the CloudFormation deployment and directly publish assets changes via:
This command only takes seconds: it directly uploads files to S3 and clears the CloudFront cache.
Configuration reference
API Gateway
severless.yml
only deploys a API Gateway v1 REST API, then the construct should use itseverless.yml
only deploys a API Gateway v2 HTTP API, then the construct should use itseverless.yml
deploys both a REST API and an HTTP API, then the user should configure which one to use:If there is no Lambda function configured to respond to HTTP requests then the construct should show an error to the user (an API Gateway is required).
Assets
The
assets
section lets users define routing for static assets (like JavaScript, CSS, images, etc.).Assets can be either whole directories, or single files:
With the example above:
https://<domain>/*
-> Lambdahttps://<domain>/css/*
-> serves the files uploaded from the localdist/css
directoryhttps://<domain>/images/*
-> serves the files uploaded from the localassets/animations
directoryhttps://<domain>/favicon.ico
-> serves the file uploaded frompublic/favicon.ico
Custom domain
This will behave similarly to the static website domain configuration.
Error pages
In case a web page throws an error, API Gateway's default
Internal Error
blank page shows up. This can be overridden by providing an HTML error page.Applications are of course free to catch errors and display custom error pages. However, sometimes even error pages and frameworks fail completely: this is where the API Gateway error page shows up.
Draft pull request
A pull request with a draft implementation is available here: #44
Beta Was this translation helpful? Give feedback.
All reactions