Deploying a Website
How to deploy a website you didn't write with Freestyle
The Freestyle Web API provides a set of tools to build, deploy and manage websites.
Guide
This guide will go through the fastest path to deploy a sample website on Freestyle using our SDKs.
Install the Freestyle Sandboxes package
First, install the package with your preferred package manager
npm i freestyle-sandboxes
pnpm i freestyle-sandboxes
bun i freestyle-sandboxes
yarn add freestyle-sandboxes
pip install freestyle
Get your API key
Go to the Freestyle Dashboard and get your API key
Deploy the website
Create a deploy script in the root of the repo with the following code:
import { FreestyleSandboxes } from "freestyle-sandboxes";
const api = new FreestyleSandboxes({
apiKey: process.env.FREESTYLE_API_KEY!, // make sure to set this
});
api
.deployWeb(
{
kind: "git",
url: "https://github.com/freestyle-sh/freestyle-base-nextjs-shadcn", // URL of the repository you want to deploy
},
{
domains: ["yourtestdomain.style.dev"],
build: true, // automatically detects the framework and builds the code
}
)
.then((result) => {
console.log("Deployed website @ ", result.domains);
});
import freestyle
client = freestyle.Freestyle("YOUR_FREESTYLE_API_KEY")
response = client.deploy_web(
src=freestyle.DeploymentSource.from_dict(
{
"kind": "git",
"url": "https://github.com/freestyle-sh/freestyle-base-nextjs-shadcn",
}
),
config=freestyle.FreestyleDeployWebConfiguration(
domains=["welcomepython.style.dev"],
build=freestyle.DeploymentBuildOptions.from_dict(True),
),
)
print(
f"Deployed website @ {response.domains}"
)
When deploying a website to Freestyle, there are two distinct parameters:
- Source: This is the code you want to deploy, it can be a Git repository, a set of files, or a link to a tarball. In this example, we're using a public Github repository that contains a Next.js App.
- Configuration: This is the configuration for the deployment, it can include the domains you want to deploy to, the entrypoint of the application, whether to build the code or deploy it as is, timeout behavior and much more. We set
build
:true
to automatically detect the framework and build the code.
Then run the file to deploy the website:
node deploy.js
python deploy.py
Semantics
Freestyle Web Deployments are bundles of code and configuration deployed to Freestyle. They are immutable, when you want to change an environment variable, configuration, or the code itself, you need to create a new deployment. They cannot be deleted. Deployments are completely decoupled from the domains they are displayed on, you can attach and detach domains from deployments at will using the Domain Mappings.
Next Steps
- If you want to deploy to custom domain, first you need to verify a domain
- If you want to deploy Expo Apps, check out our Expo guide
- If you want to deploy a Next.js App, check out our Next.js guide
- If you need advanced configuration options, check out the Configuration guide