docs: add "Server configuration" concept explanation (#1293)

This commit is contained in:
Reed von Redwitz
2023-06-15 11:37:23 +02:00
committed by GitHub
parent ce0eda7654
commit f833c7262d
2 changed files with 97 additions and 1 deletions
+95
View File
@@ -0,0 +1,95 @@
---
description: |
The ability to configure the core Fresh server leads to its flexibility.
---
In this page we discuss how the server can be configured during startup.
The signature of the primary method looks like this:
```ts
export async function start(routes: Manifest, opts: StartOptions = {});
```
## Options
`Manifest` comes from `fresh.gen.ts`, so nothing to do there. `opts` is where
things get interesting. `StartOptions` looks like this:
```
export type StartOptions = ServeInit & FreshOptions & {
/**
* UNSTABLE: use the `Deno.serve` API as the underlying HTTP server instead of
* the `std/http` API. Do not use this in production.
*
* This option is experimental and may be removed in a future Fresh release.
*/
experimentalDenoServe?: boolean;
};
```
You can play around with `Deno.serve` if you'd like, but heed the warning. The
good stuff is really in...
```ts
export interface FreshOptions {
render?: RenderFunction;
plugins?: Plugin[];
staticDir?: string;
router?: RouterOptions;
}
```
And for brevity here are the remaining two types:
```ts
export type RenderFunction = (
ctx: RenderContext,
render: InnerRenderFunction,
) => void | Promise<void>;
export interface RouterOptions {
/**
* @default {false}
*/
trailingSlash?: boolean;
}
```
## Plugins
See the [docs](./docs/concepts/plugins) on this topic for more detail. But for
completion, you can do something like this to load plugins:
```ts
await start(manifest, { plugins: [twindPlugin(twindConfig)] });
```
## StaticDir
This allows you to specify the location where your site's static assets are
stored. Here's an example:
```ts
await start(manifest, { staticDir: "./custom_static" });
```
## Render
This is by far the most complicated option currently available. It allows you to
configure how your components get rendered.
A detailed, concrete example of this is changing the language of the `<html>`
tag. See the documentation [here](./docs/examples/setting-the-language.md).
## RouterOptions
### TrailingSlash
By default Fresh uses URLs like `https://www.example.com/about`. If you'd like,
you can configure this to `https://www.example.com/about/` by using the
`trailingSlash` setting.
```ts
await start(manifest, { router: { trailingSlash: true } });
```
+2 -1
View File
@@ -31,7 +31,8 @@
["deployment", "Deployment"],
["plugins", "Plugins"],
["updating", "Updating Fresh"],
["app-wrapper", "Application wrapper"]
["app-wrapper", "Application wrapper"],
["server-configuration", "Server configuration"]
]
},
"integrations": {