πŸ‘€ Our most exciting product launch yet πŸš€ Join us May 8th for Sanity Connect

Troubleshooting Github Codespaces and Sanity integration

1 replies
Last updated: Mar 2, 2023
Hello everyone,
I'm experiencing some difficulties using Github's Codespaces and Sanity. While I'm able to initialize and code a Sanity project within a Codespace, I'm having trouble starting the dev server with "npm run dev" as the page keeps loading indefinitely. I'm assuming this is related to the port forwarding logic that Codespaces use. Have any of you encountered a similar issue?

Thank you.
Mar 2, 2023, 12:58 PM
Okay I fixed it and posting the solution in case anyone has the same issue:
By default, GitHub Codespaces forwards ports 3000, 4000, and 5000 to the host machine, which means that if your Sanity project is running on a different port, you may need to configure port forwarding to access it from your local machine.
To configure port forwarding in Codespaces, you can add a
.devcontainer/devcontainer.json
file to your project with the following configuration:
{
  "name": "Sanity Project",
  "appPort": 3333,
  "appPortAutoForward": true
}
Then, you'll probably get a CORS issue: "To access your content, you need to add the following URL as a CORS origin to your Sanity project".

To resolve this issue, you need to add the domain that you're trying to access as a CORS origin in your Sanity project. Here are the steps to do that:
1. Log in to your Sanity project dashboard.
2. Click on the "API Settings" button in the left-hand menu.
3. In the "CORS Origins" section, click on the "Add new origin" button.
4. Enter the domain that you're trying to access in the "Origin" field. For example`
https://127.0.0.1:3333 `5. Click on the "Save" button to save your changes.
Once you've added the domain as a CORS origin, you should be able to access the data from your Sanity project without any issues.
Mar 2, 2023, 1:15 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?