Stormkit is able to handle the path rewrites and redirects on the load balancer level. In order to make use of this feature, create a stormkit.config.yml file at root level of your repository. This file will be parsed on each deployment, hence if you change this file previous deployments won't be affected. The syntax is as follows:
- from: <string>
|From||The URL or path to be rewritten/redirected. It accepts a pattern string.|
'*' matches any sequence of non-Separator characters
|To||The destination URL or path.|
|Status||The redirect status. When 'From' is a relative path, it defaults to an empty value and when it's empty the path will be rewritten. When 'From' is a host name, it defaults to 302.|
|Html||Specifies if the assets should also be considered for this rewrite/redirect. If true, the assets won't be redirected. Any file that has not an .html extension and has not an empty mime type is considered as a static asset. This variable is used only when 'From' is a path and not an absolute URL.|
|Cdn||Tells Stormkit that this request should be served from the CDN and not from the lambdas.|
|Replace||Speficies whether a string replace should be used while redirecting. When used with the `status` field, it will replace the `from` value with the `to` value.|
|Host||Restricts the redirect rule to the specified host name.|
- from: stormkit.io
With replace: true we basically tell Stormkit to keep the URL.
For instance when it's true,https://stormkit.io/docs will be redirected to https://www.stormkit.io/docs, when it's false it will be redirected tohttps://www.stormkit.io.
- from: /dist/*
You can rewrite paths by using the combination of* in the from setting andreplace being set totrue. This will tell Stormkit to replace anything that matches the 'from' statement with the 'to' statement, and keep the rest of the url.
Examples with the above settings:
- from: /*
The above example will rewrite all requests to index.html. It applies only to CDN requests since cdn is set true. This is useful for single page applications.
- from: /favicon.ico
By default Stormkit provides an endpoint to serve files from the CDN. Sometimes however we need to serve files from the same domain. If you're using an isomorphic application, requests to the same domain will tell Stormkit to forward the request to the lambda function. Luckily, by setting the cdn config true we tell Stormkit to serve the files from the CDN.
- from: /dist/*
When the host parameter is specified, Stormkit will check that the request host matches the parameter value. This is useful when you have a monorepo with multiple apps hosted and you want to make sure that the redirect applies only to given hosts.