Configuration
How dev server configuration works and how to customize it.
Dev Server configuration allows you to define how and what a dev server runs. They enable Freestyle Dev Servers to adapt to any project structure and requirements you need.
Where they live
Dev Server configs can live in 3 places: On the Git, on the branch, or on the request for a dev server itself.
When you request a dev server, we'll merge the specific configuration you requested, with the configuration on the branch, and then with the configuration on the Git repo itself, prioritizing the most specific configuration.
This means you can set project level variables on a git repo, branch specific repos for each branch, and session specific variables when you request the dev server.
Configuration Options
The configuration options available are:
Ports
You can define which ports should be exposed by the dev server. Every dev server is given a single URL, and the option to expose two ports publicly: 443 on HTTPS and 8081 on HTTP. You can map these ports to whatever internal ports your applications are running on.
We default to exposing internal port 3000 on 443.
Ports are submitted as an array of objects, like so:
"ports": [
{
"targetPort": 3000,
"port": 443
},
{
"targetPort": 3000,
"port": 8081
}
]
Where targetPort
is the internal port your application is running on, and port
is the external port you want to expose.
Environment Variables
You can define environment variables to be set in the dev server. These are set as key/value pairs, like so:
"env": {
"API_URL": "https://api.example.com",
"NODE_ENV": "development"
}
To hide an environment variable on a Git repository from a branch or session, you can set that key's value to null
in the more specific configuration.
"env": {
"API_URL": null
}
Commands
There are a few different commands you can configure in the dev server configuration.
devCommand
: The command that runs the development server. We'll manage this command and ensure it stays running. By default we usenpm run dev
installCommand
: The command that runs to install dependencies. By default we usenpm install --force
Timeout
The amount of time after network traffic ends that we wait before shutting down the dev server. By default this is set to 5 minutes (300 seconds). If you want it to never time out you can set the timeout to null
.
"timeout": null
Preset
You can set a preset to quickly configure a dev server for a specific framework. The currently available presets are:
nextJs
vite
expo
Configuring Git Repositories
You can set up a dev server configuration for a new Git Repository by setting its devServers
property in your request. Any configuration you set here will be used for all branches and sessions on this repository, unless overridden by a branch or session specific configuration.
const { repoId } = await freestyle.createGitRepository({
name: "Example Repository",
// This will make it easy for us to clone the repo during testing.
// The repo won't be listed on any public registry, but anybody
// with the uuid can clone it. You should disable this in production.
public: true,
source: {
url: "https://github.com/freestyle-sh/freestyle-next",
type: "git",
},
devServers: {
timeout: 600,
envVars: {
EXAMPLE_VAR: "example value",
},
preset: "nextJs", // Set the preset for the framework you're using, this will automatically configure the dev server for you
}
});
You can also fetch a repository's configuration, or set it on a per branch basis after the fact using the API.