|
| 1 | +--- |
| 2 | +title: App Configuration |
| 3 | +description: Configure your app with redwood.toml |
| 4 | +--- |
| 5 | + |
| 6 | +# App Configuration: redwood.toml |
| 7 | + |
| 8 | +One of the premier places you can configure your Redwood app is `redwood.toml`. By default, `redwood.toml` lists the following configuration options: |
| 9 | + |
| 10 | +```toml title="redwood.toml" |
| 11 | +[web] |
| 12 | + title = "Redwood App" |
| 13 | + port = 8910 |
| 14 | + apiUrl = "/.redwood/functions" |
| 15 | + includeEnvironmentVariables = [] |
| 16 | +[api] |
| 17 | + port = 8911 |
| 18 | +[browser] |
| 19 | + open = true |
| 20 | +[notifications] |
| 21 | + versionUpdates = ["latest"] |
| 22 | +``` |
| 23 | + |
| 24 | +These are listed by default because they're the ones that you're most likely to configure, but there are plenty more available. |
| 25 | + |
| 26 | +You can think of `redwood.toml` as a frontend for configuring Redwood's build tools. |
| 27 | +For certain options, instead of having to configure build tools directly, there's quick access via `redwood.toml`. |
| 28 | + |
| 29 | +## [web] |
| 30 | + |
| 31 | +| Key | Description | Default | |
| 32 | +| :---------------------------- | :--------------------------------------------------------- | :---------------------- | |
| 33 | +| `title` | Title of your Redwood app | `'Redwood App'` | |
| 34 | +| `port` | Port for the web server to listen at | `8910` | |
| 35 | +| `apiUrl` | URL to your api server. This can be a relative URL in which case it acts like a proxy, or a fully-qualified URL | `'/.redwood/functions'` | |
| 36 | +| `includeEnvironmentVariables` | Environment variables made available to the web side during dev and build | `[]` | |
| 37 | +| `host` | Hostname for the web server to listen at | Defaults to `'0.0.0.0'` in production and `'::'` in development | |
| 38 | +| `apiGraphQLUrl` | URL to your GraphQL function | `'${apiUrl}/graphql'` | |
| 39 | +| `apiDbAuthUrl` | URL to your dbAuth function | `'${apiUrl}/auth'` | |
| 40 | +| `sourceMap` | Enable source maps for production builds | `false` | |
| 41 | +| `a11y` | Enable storybook `addon-a11y` and `eslint-plugin-jsx-a11y` | `true` | |
| 42 | + |
| 43 | +### Customizing the GraphQL Endpoint |
| 44 | + |
| 45 | +By default, Redwood derives the GraphQL endpoint from `apiUrl` such that it's `${apiUrl}/graphql`, (with the default `apiUrl`, `./redwood/functions/graphql`). |
| 46 | +But sometimes you want to host your api side somewhere else. |
| 47 | +There's two ways you can do this: |
| 48 | + |
| 49 | +1. Change `apiUrl`: |
| 50 | + |
| 51 | +```toml title="redwood.toml" |
| 52 | +[web] |
| 53 | + apiUrl = "https://api.coolredwoodapp.com" |
| 54 | +``` |
| 55 | + |
| 56 | +Now the GraphQL endpoint is at `https://api.coolredwoodapp.com/graphql`. |
| 57 | + |
| 58 | +2. Change `apiGraphQLUrl`: |
| 59 | + |
| 60 | +```diff title="redwood.toml" |
| 61 | + [web] |
| 62 | + apiUrl = "/.redwood/functions" |
| 63 | ++ apiGraphQLUrl = "https://api.coolredwoodapp.com/graphql" |
| 64 | +``` |
| 65 | + |
| 66 | +### Customizing the dbAuth Endpoint |
| 67 | + |
| 68 | +Similarly, if you're using dbAuth, you may decide to host it somewhere else. |
| 69 | +To do this without affecting your other endpoints, you can add `apiDbAuthUrl` to your `redwood.toml`: |
| 70 | + |
| 71 | +```diff title="redwood.toml" |
| 72 | + [web] |
| 73 | + apiUrl = "/.redwood/functions" |
| 74 | ++ apiDbAuthUrl = "https://api.coolredwoodapp.com/auth" |
| 75 | +``` |
| 76 | + |
| 77 | +:::tip |
| 78 | + |
| 79 | +If you host your web and api sides at different domains and don't use a proxy, make sure you have [CORS](./cors.md) configured. |
| 80 | +Otherwise browser security features may block client requests. |
| 81 | + |
| 82 | +::: |
| 83 | + |
| 84 | +### includeEnvironmentVariables |
| 85 | + |
| 86 | +`includeEnvironmentVariables` is the set of environment variables that should be available to your web side during dev and build. |
| 87 | +Use it to include env vars like public keys for third-party services you've defined in your `.env` file: |
| 88 | + |
| 89 | +```toml title="redwood.toml" |
| 90 | +[web] |
| 91 | + includeEnvironmentVariables = ["PUBLIC_KEY"] |
| 92 | +``` |
| 93 | + |
| 94 | +```text title=".env" |
| 95 | +PUBLIC_KEY=... |
| 96 | +``` |
| 97 | + |
| 98 | +Instead of including them in `includeEnvironmentVariables`, you can also prefix them with `REDWOOD_ENV_` (see [Environment Variables](environment-variables.md#web)). |
| 99 | + |
| 100 | +:::caution `includeEnvironmentVariables` isn't for secrets |
| 101 | + |
| 102 | +Don't make secrets available to your web side. Everything in `includeEnvironmentVariables` is included in the bundle. |
| 103 | + |
| 104 | +::: |
| 105 | + |
| 106 | +## [api] |
| 107 | + |
| 108 | +| Key | Description | Default | |
| 109 | +| :------------- | :---------------------------------- | :------------------------- | |
| 110 | +| `port` | Port for the api server to listen at | `8911` | |
| 111 | +| `host` | Hostname for the api server to listen at | Defaults to `'0.0.0.0'` in production and `'::'` in development | |
| 112 | +| `debugPort` | Port for the debugger to listen at | `18911` | |
| 113 | +| `serverConfig` | [Deprecated; use the [server file](./docker.md#using-the-server-file) instead] Path to the `server.config.js` file | `'./api/server.config.js'` | |
| 114 | + |
| 115 | +## [browser] |
| 116 | + |
| 117 | +```toml title="redwood.toml" |
| 118 | +[browser] |
| 119 | + open = true |
| 120 | +``` |
| 121 | + |
| 122 | +Setting `open` to `true` opens your browser to `http://${web.host}:${web.port}` (by default, `http://localhost:8910`) after the dev server starts. |
| 123 | +If you want your browser to stop opening when you run `yarn rw dev`, set this to `false`. |
| 124 | +(Or just remove it entirely.) |
| 125 | + |
| 126 | +There's actually a lot more you can do here. For more, see Vite's docs on [`preview.open`](https://vitejs.dev/config/preview-options.html#preview-open). |
| 127 | + |
| 128 | +## [generate] |
| 129 | + |
| 130 | +```toml title="redwood.toml" |
| 131 | +[generate] |
| 132 | + tests = true |
| 133 | + stories = true |
| 134 | +``` |
| 135 | + |
| 136 | +Many of Redwood's generators create Jest tests or Storybook stories. |
| 137 | +Understandably, this can be lot of files, and sometimes you don't want all of them, either because you don't plan on using Jest or Storybook, or are just getting started and don't want the overhead. |
| 138 | +These options allows you to disable the generation of test and story files. |
| 139 | + |
| 140 | +## [cli] |
| 141 | + |
| 142 | +```toml title="redwood.toml" |
| 143 | +[notifications] |
| 144 | + versionUpdates = ["latest"] |
| 145 | +``` |
| 146 | + |
| 147 | +There are new versions of the framework all the time—a major every couple months, a minor every week or two, and patches when appropriate. |
| 148 | +And if you're on an experimental release line, like canary, there's new versions every day, multiple times. |
| 149 | + |
| 150 | +If you'd like to get notified (at most, once a day) when there's a new version, set `versionUpdates` to include the version tags you're interested in. |
| 151 | + |
| 152 | +## Using Environment Variables in `redwood.toml` |
| 153 | + |
| 154 | +You may find yourself wanting to change keys in `redwood.toml` based on the environment you're deploying to. |
| 155 | +For example, you may want to point to a different `apiUrl` in your staging environment. |
| 156 | + |
| 157 | +You can do so with environment variables. |
| 158 | +Let's look at an example: |
| 159 | + |
| 160 | +```toml title="redwood.toml" |
| 161 | +[web] |
| 162 | + // highlight-start |
| 163 | + title = "App running on ${APP_TITLE}" |
| 164 | + port = "${PORT:8910}" |
| 165 | + apiUrl = "${API_URL:/.redwood/functions}" |
| 166 | + // highlight-end |
| 167 | + includeEnvironmentVariables = [] |
| 168 | +``` |
| 169 | + |
| 170 | +This `${<envVar>:[fallback]}` syntax does the following: |
| 171 | + |
| 172 | +- sets `title` by interpolating the env var `APP_TITLE` |
| 173 | +- sets `port` to the env var `PORT`, falling back to `8910` |
| 174 | +- sets `apiUrl` to the env var `API_URL`, falling back to `/.redwood/functions` (the default) |
| 175 | + |
| 176 | +That's pretty much all there is to it. |
| 177 | +Just remember two things: |
| 178 | + |
| 179 | +1. fallback is always a string |
| 180 | +2. these values are interpolated at build time |
| 181 | + |
| 182 | +## Running in a Container or VM |
| 183 | + |
| 184 | +To run a Redwood app in a container or VM, you'll want to set both the web and api's `host` to `0.0.0.0` to allow network connections to and from the host: |
| 185 | + |
| 186 | +```toml title="redwood.toml" |
| 187 | +[web] |
| 188 | + host = '0.0.0.0' |
| 189 | +[api] |
| 190 | + host = '0.0.0.0' |
| 191 | +``` |
| 192 | + |
| 193 | +You can also configure these values via `REDWOOD_WEB_HOST` and `REDWOOD_API_HOST`. |
| 194 | +And if you set `NODE_ENV` to production, these will be the defaults anyway. |
0 commit comments