Skip to content

ServerlessReact.dev

Student Login

Going to production

You've built a cool app, time to put it in production! We'll make it available to the world and ensure you don't spoil production data next time you try something.

Prod vs. Dev on backend

use dev and prod configs

We use this helpful bash script to run yarn deploy and yarn deploy prod in the future.

STAGE=${1:-dev}
yarn build
NODE_ENV=$STAGE sls deploy --stage $STAGE

see separate deploy

Prod on frontend

The tricky part here is telling the webapp how to connect to different versions of the backend. I'll show you 3 approaches with the final one that worked for me.

Gatsby encourages .env files, which only work when you compile locally.

Zeit encourages "zeit secrets", which only work during build time.

We end up with JSON config files that always work, but aren't the most secure since you check them into your code.

With Gatsby .env approach

connect prod/dev build-time graphql

runtime .env configs

setup zeit manual deploys

Using Zeit secrets

alias to prod domain

move runtime config to static queries

use json files to feed configs

it works in prod, yay

Created bySwizecwith ❤️