Express Template
Outline
An Express Site using Handlebars templates on AWS API Gateway behind Cloudfront.
Setup & Run
npm install
in the root of the project
cd api
- Change name of the serverless service and update any non-unique infrastructure names.
npm run deploy
npm start
will start the local environment
http://localhost:4000/dev/public/
open url in browser - trailing slash is important for links (in local)
Considerations
- Limitations on size of payloads from API (6mb Lambda limit is the bottleneck). The Lambda Express server will compress payloads by default to alleviate the issue.
- Expensive to not cache static content like images, alternative solution likely needed
- Cloudfront can cache specific file types to ease load on API Gateway, cache needs invalidating if they change however
Technology
- Express
- Handlebars https://handlebarsjs.com/
- Serverless Framework
- TypeScript
- Esbuild
- AWS Gateway
- AWS Lambda
- AWS Cloudfront (CDN)
- AWS DynamoDB
- Serverless Offline
- DynamoDB Local
Issues
Local Development
- Relative links on the pages seem to need to have a trailing slash on the current URL the browser is on or they will not link to a valid page address. If you have this problem try adding a slash to your current URL. e.g.
http://localhost:4000/dev/public/
.
- Due to API Gateway not working correctly with a root assignment for a lambda (
/
) the entire site is moved on path up under /public
so that we can reference /public/
as root. The Cloudformation Origin then sets an origin path of /dev/public
so that when you hit the Cloudfront distribution it is seamless serving /public/
as https://d23g17ecl2q2ol.cloudfront.net/
.
Back