Best practices for deploying a website

I’m building a website in which needs to collect user sign up information. Right now I’m hosting the static files (including index.html and main.js) on s3 and sending HTTP post requests to an AWS lambda endpoint which uses mongoose to insert the objects into a mongoDB atlas cluster. So I use serverless-finch to deploy the static assets and serverless to deploy the lambda functions.

So far everything is working alright except for the api gateway endpoint which is hard-coded into the main.js file, which is a bad thing. I’d like to remove that, so I was wondering if there was a way to do so conveniently? Maybe there’s a way for serverless deploy to output the api gateway string to a file that serverless client deploy can pick up? Or should I use some custom build tool?

It’s my first time using this framework (or doing any sort of web dev) so for all I know I could be doing everything wrong. Any advice, specific or general is appreciated!

I have a React app with a Serverless backend. Early on the decision was made to keep them completely separate. They’re actually in two different repos.

The React app is built using Webpack and deployed to S3 using the AWS command line tool. To keep everything repeatable I have npm scripts (npm run deploy is all I need to run).

Each stage has it’s own Webpack config and the define plugin allows me to set different API endpoints for each stage. Yes, it means I need manually put the API endpoint into the config but that doesn’t change once the stage is setup.

1 Like