Streamlining Integration of Single Page Applications (SPA) into Existing Backends: Tools and Best Practices
Table of Contents
Background
When integrating SPA into an existing backend there are a number of tools that can be used to reduce the pain of performing the work.
Tools
- Chrome "Copy as cUrl" https://developers.google.com/web/updates/2015/05/replay-a-network-request-in-curl?hl=en
Process
- Provide explicit notes on the exact HTTP expectations
- Provide notes on the routing expected from the application server
- Provide a single case of the request without and existing state
- Whitelist the route mapping through the proxy server
- Disable any mock front-end API
- Establish monitoring to go with #1
Integration
We'll focus initally on a scenario where we're able to have an explicit build step and that we want to have the developer experience be as seemless as possible when in either Rails or during the application development.
- Rails provides some core functionality
- Rails also provides api
- Node provides a place for live loading files
- Node provides a build infrastructure for creating a single main.js
Options
Symlink the deployments in public
Copy the files and check into version control in public
Copy the file and check into app/assets
Deploy build to S3, public, with day Expires
S3 then CloudFront with invalidations
S3, nginx proxy with gzip, CloudFront
NPM in Rails
SPA as gem to AssetPipeline
Testing
- Name, Size (compressed), Size (uncompressed), Expires