Hacker News new | ask | show | jobs
by cordite 2321 days ago
A problem my team hits with micro projects with this is: virtual routes like `/login` doesn’t map to a file. What can be done about that?
5 comments

Like a SPA? You use a something like react router and set the S3 error page to your index. I've deployed many SPAs to AWS S3/ Cloudfront. You have to handle the 404 page in app

Here's a SO post https://stackoverflow.com/questions/51218979/react-router-do...

/login makes me think your website isn't really static.

Regardless, you can use extensionless links with your static website if you rename the file from login.html to login, then change the file metadata to Content-Type: 'text/html'

Why would it not be static? It could be a static site making a request to an API to log in?
You can add an error behaviour in cloudfront that defaults the 404 behaviours to the index page. If you also add the index and error of the S3 config to the same index page it all works perfectly.

We have multiple React sites deployed this way to S3/Cloudfront with react-router and experience no issues.

You can also use Lambda@Edge with CloudFront to do any kind of logic required, like redirects, rewrites, etc...
Most servers will route /login/index.html to /login