This guide shows you how to deploy a Sanity Studio application to Edgio.
Sanity Studio is a single page app (SPA) written in React, where you can configure the document types and input fields, with simple JavaScript objects. This guide will walk you through how to deploy Sanity Studio with Edgio in four simple steps.
Prerequisites
Setup requires:
- An Edgio account. Sign up for free.
- An Edgio property. Learn how to create a property.
- Node.js. View supported versions and installation steps.
- Edgio CLI.
Install the Edgio CLI
If you have not already done so, install the Edgio CLI.
Bash
1npm i -g @edgio/cli@^6.0.0
Create a new Sanity Studio app
First, install the Sanity CLI:
Bash
1npm i -g @sanity/cli
To initiate a new project and download the Studio code to your computer, run the following in the command line:
Bash
1sanity init
The Sanity CLI will walk you through the necessary steps to set up a project, letting you choose a schema template. When you’re done with these steps, the CLI will download the source code and configuration to get you started. To start a local development server, cd into the project folder and run the following command:
Bash
1sanity start
Configuring your Sanity Studio app for Edgio
Initialize your project
In the root directory of your project run
edgio init
:Bash
1edgio init --edgioVersion ^6.0.0
This will automatically update your
package.json
and add all of the required Edgio dependencies and files to your project. These include:- The
@edgio/core
package - Allows you to declare routes and deploy your application on Edgio - The
@edgio/prefetch
package - Allows you to configure a service worker to prefetch and cache pages to improve browsing speed edgio.config.js
- A configuration file for Edgioroutes.js
- A default routes file that sends all requests to Sanity Studio.
Configure the routes
Update
routes.js
at the root of your project to the following:JavaScript
1// This file was added by edgio init.2// You should commit this file to source control.34import { Router } from '@edgio/core/router'56export default new Router()7 // Create serveStatic route for each file in the folder dist with a cache-control header of 's-maxage=315360000'8 .static('dist')9 .fallback(({ appShell }) => {10 appShell('dist/index.html')11 })
Refer to the CDN-as-code guide for the full syntax of the
routes.js
file and how to configure it for your use case.Run the Sanity Studio app locally on Edgio
Create a production build of your app by running the following in your project’s root directory:
Bash
1npm run build
Set default port number for the app to run on 3333:
Bash
1set PORT=3333 # windows2export PORT=3333 # linux
Test your app with the Sites on your local machine by running the following command in your project’s root directory:
Bash
1edgio dev
Load the site http://127.0.0.1:3333
Deploying
Create a production build of your app by running the following in your project’s root directory:
Bash
1npm run build
Deploy your app to the Sites by running the following command in your project’s root directory:
Bash
1edgio deploy
Refer to the Deployments guide for more information on the
deploy
command and its options.Post Deployment Whitelisting
Once Sanity Studio is deployed, you will need to add it’s URL to Sanity’s CORS origins settings. You can do this from the command line:
Bash
1sanity cors add https://your-url.layer0-limelight.link --credentials
Alternatively, you can navigate to manage.sanity.io, find your project and under Settings > API, add the Studio URL to the CORS origins list. You should allow credentials as the Studio requires authentication for added security.