Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(config): allow ws config #1249

Merged
merged 3 commits into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions docs/content/4.api/3.configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export default defineNuxtConfig({
})
```


## `base`

- Type: `String`{lang=ts}
Expand Down Expand Up @@ -179,7 +178,7 @@ Nuxt Content uses [Shiki](https://github.com/shikijs/shiki) to provide syntax hi

### `highlight` options

| Option | Default | Description |
| Option | Type | Description |
| ----------------- | :--------: | :-------- |
| `theme` | `ShikiTheme` | The [color theme](https://github.com/shikijs/shiki/blob/main/docs/themes.md) to use |
| `preload` | `ShikiLang[]` | The [preloaded languages](https://github.com/shikijs/shiki/blob/main/docs/languages.md) available for highlighting. |
Expand Down Expand Up @@ -211,3 +210,14 @@ List of locale codes. This codes will be used to detect contents locale.
- Default: `undefined`{lang=ts}

Default locale for top level contents. Module will use first locale code from `locales` array if this option is not defined.

## `ws`

Nuxt Content uses a WebSocket server in development to allow hot reloading of your content files.

### `ws` options

| Option | Default | Description |
| ----------------- | :--------: | :-------- |
| `port` | `4000` | Select the port used for the WebSocket server. |
| `showUrl` | `false` | Toggle URL display in dev server boot message. |
19 changes: 18 additions & 1 deletion src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,19 @@ export interface ModuleOptions {
* @default undefined
*/
defaultLocale: string
/**
* WebSocket server configuration.
*/
ws: {
Tahul marked this conversation as resolved.
Show resolved Hide resolved
/**
* @default 4000
*/
port: number
/**
* @default false
*/
showUrl: boolean
}
}

interface ContentContext extends ModuleOptions {
Expand All @@ -181,6 +194,10 @@ export default defineNuxtModule<ModuleOptions>({
defaults: {
base: '_content',
watch: true,
ws: {
port: 4000,
showUrl: false
},
sources: ['content'],
ignores: ['\\.', '-'],
locales: [],
Expand Down Expand Up @@ -416,7 +433,7 @@ export default defineNuxtModule<ModuleOptions>({
})

// Listen dev server
const { server, url } = await listen(() => 'Nuxt Content', { port: 4000, showURL: false })
const { server, url } = await listen(() => 'Nuxt Content', options.ws)
server.on('upgrade', ws.serve)

// Register ws url
Expand Down