Quickstart

A quick dive into getting started with Lore

Step 4: Redeploy to Production

In this step we'll publish our production build to the web.

There is no branch for this step because it does not modify any code.

Redeploy to Now

With that change in place, redeploy the application to Now, but this time using the deploy:production script, which will also build the application before deploying it:

npm run deploy:production

Once the application is deployed, you'll get another random URL like lore-quickstart-jxuyvmeneg.now.sh. Copy that URL, and alias it to the domain you chose previously:

now alias lore-quickstart-jxuyvmeneg.now.sh lore-quickstart.now.sh

We just performed a zero-downtime deploy.

With the aliasing complete, navigate to that URL. This time, after you log in, you'll be redirected back to the production website, and the application will work like expect, only now it's hosted on a publicly accessible domain.

Modifying the Production Config API Server

It's important to highlight that if you look at the network requests for the application running on surge, you'll notice it's still making API calls to localhost:1337. This is important to callout because it means the application will only work for YOU, and only while the lore-tutorial-api server is running.

If you're deploying the application to production for real, it's likely using a different API server, and you'll want the production version of the application to behave different that when running on localhost for development.

To do that, open up config/env/production.js and set the production server for the default connection. For example, let's say the production API server is located at https://api.example.com. To set that for the production build, edit your production.js config to look like this:

export default {

  connections: {
    default: {
      apiRoot: 'https://api.example.com'
    }
  }

};
export default {

  connections: {
    default: {
      apiRoot: 'https://api.example.com'
    }
  }

}
export default {

  connections: {
    default: {
      apiRoot: 'https://api.example.com'
    }
  }

}

With that change in place, if you run npm run build:prod to rebuild the application, and then redeploy it to surge using the shortcut command (like surge dist lore-quickstart.surge.sh), you'll see the application will automatically change with API server it tries to communicate with, but only in production. When running on localhost for development the API server used will still be localhost:1337.

Visual Check-in

If everything went well, your application should still look like this (exactly the same) but will now be hosted on Now and built for production!

Code Changes

There are no code changes required for this step.

Next Steps

In the next section we'll talk about next steps.