How to deploy FTW to production
This guide describes how to set up a production deployment for Flex Template for Web (FTW).
Table of Contents
A production environment hosts and executes the code that runs your live marketplace and serves it to the public internet. The version of your marketplace intended for real-life use with real money runs in the production environment. Typically, alongside your production environment, you will also host another version of your client environment: a test environment.
Having two environments is a common practice in software development. The test environment is a clone of the production environment intended for testing new features before being deployed to production. Once a development team deems a feature production-ready, i.e. fit for a live audience, they can deploy it to production. A workflow like this helps prevent bugs and unfinished code from being released to your users.
Sharetribe Flex offers three different environment types. You should connect your client application with the corresponding marketplace environment, i.e. your client environment intended for testing should use environment variables that point to your test environment in Flex.
There are many hosting providers to choose from when considering where to host your marketplace. Our official recommendation is to host your marketplace on Heroku or Render for a hassle-free installation. However, you are free to host your marketplace elsewhere. Flex Templates for Web (FTW) should be compatible with any hosting provider as long as they allow you to run a Node.js/Express server. Many essential functions in FTW rely on a small Node.js/Express server (such as server-side rendering, SSO and transitioning privileged transactions). Serverless service providers such as Netlify and Vercel are unsuitable for FTW as they don't allow you to host a server.
When choosing a hosting provider, you should not only consider the cheapest option. Scalability, tools, service-level agreements and available computing resources are examples of factors that should weigh in when choosing a hosting provider. It is also possible that hosting providers' prices and services may change over time, e.g. Heroku is discontinuing its popular free tier on October 26th, 2022.
As of the time of writing, Render and Fly.io continue to provide a free tier, which you can use, e.g. to host a testing environment. You will have to move to a paid plan for a production-level deployment to ensure consistent uptime and computing resources for your marketplace. Other alternatives you can look into include AWS, Google Cloud, Digital Ocean and Microsoft Azure.
Deploying your marketplace to production is a three-step process:
For a full list of possible environment variables, see the FTW Environment configuration variables reference for more information. To deploy your marketplace, you need to add at least the following variables:
Use the value 'production'.
You must set a port if the production environment does not set one by default. Heroku and Render define a port automatically.
Your client ID. You can find it in Flex Console.
Your client secret. You can find it in Flex Console.
Stripe publishable API key for generating tokens with Stripe API. You find it on the Stripe API keys page. You will also need to add the secret key in Flex Console.
If using Mapbox, you will need to define this environment variable. Sign
up for Mapbox and go to the
account page. Then click
Create access token. See the
How to set up Mapbox for FTW guide
for more information.
This is the canonical root URL of the marketplace. For example:
https://the-name-of-your-app.herokuapp.com. FTW uses the canonical
root URL for social media sharing and SEO optimization.
This is the currency your marketplace uses formatted in the Marketplace as ISO 4217 currency code. For example, USD, EUR, CAD, AUD, etc.
Running the following command builds the app for production to the build folder. It correctly bundles React in production mode and optimizes the build for the best performance.
After this, your app is ready to be deployed.
To start the server, you need to run: