Skip to content

Can specify a port of the dev ws #1244

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

Closed
guille-moe opened this issue Jun 10, 2022 · 1 comment · Fixed by #1249
Closed

Can specify a port of the dev ws #1244

guille-moe opened this issue Jun 10, 2022 · 1 comment · Fixed by #1249
Assignees
Labels
enhancement New feature or request

Comments

@guille-moe
Copy link

Is your feature request related to a problem? Please describe

The 4000 port is used by Nuxt Content v2 when I start a Nuxt dev server which can be already in use or require a port forwarding (both in my case).
There is no hint anywhere that Nuxt Content need a port to work.

Describe the solution you'd like

Can specify a port number in the content Nuxt config object.

Describe alternatives you've considered

For now I shutdown my other project which use 4000 and map the port 4000 of the docker container running the Nuxt dev server.

Additional context

https://github.com/nuxt/content/blob/main/src/module.ts#L419

I am not so sure what this imply but I guess I can try work on this to do a PR to add a port in ModuleOptions with a default to 4000 to specify the port for Listhen.
Tell me what kind of change will be relevant, I can try to implement something.

@guille-moe guille-moe added the enhancement New feature or request label Jun 10, 2022
@nozomuikuta
Copy link
Collaborator

@guille-moe

Although I'm not so familiar with the current implementation, here are some information for you.
I hope these information helps you somehow.


Goal: Add option(s) to have a control on Nuxt Content's WebSocket server

First, you need to change interface of the module options.

content/src/module.ts

Lines 38 to 161 in 8cab297

export interface ModuleOptions {
/**
* Base route that will be used for content api
*
* @default '_content'
*/
base: string
/**
* Disable content watcher and hot content reload.
* Note: Watcher is a development feature and will not includes in the production.
*
* @default true
*/
watch: boolean
/**
* Contents can located in multiple places, in multiple directories or even in remote git repositories.
* Using sources option you can tell Content module where to look for contents.
*
* @default ['content']
*/
sources: Array<string | MountOptions>
/**
* List of ignore pattern that will be used for excluding content from parsing and rendering.
*
* @default ['\\.', '-']
*/
ignores: Array<string>
/**
* Content module uses `remark` and `rehype` under the hood to compile markdown files.
* You can modify this options to control its behavior.
*/
markdown: {
/**
* Whether MDC syntax should be supported or not.
*
* @default true
*/
mdc?: boolean
/**
* Control behavior of Table of Contents generation
*/
toc?: {
/**
* Maximum heading depth that includes in the table of contents.
*
* @default 2
*/
depth?: number
/**
* Maximum depth of nested tags to search for heading.
*
* @default 2
*/
searchDepth?: number
},
/**
* Tags will be used to replace markdown components and render custom components instead of default ones.
*
* @default {}
*/
tags?: Record<string, string>
/**
* Register custom remark plugin to provide new feature into your markdown contents.
* Checkout: https://github.com/remarkjs/remark/blob/main/doc/plugins.md
*
* @default []
*/
remarkPlugins?: Array<string | [string, MarkdownPlugin]> | Record<string, false | MarkdownPlugin>
/**
* Register custom remark plugin to provide new feature into your markdown contents.
* Checkout: https://github.com/rehypejs/rehype/blob/main/doc/plugins.md
*
* @default []
*/
rehypePlugins?: Array<string | [string, MarkdownPlugin]> | Record<string, false | MarkdownPlugin>
}
/**
* Content module uses `shiki` to highlight code blocks.
* You can configure Shiki options to control its behavior.
*/
highlight: false | {
/**
* Default theme that will be used for highlighting code blocks.
*/
theme?: ShikiTheme,
/**
* Preloaded languages that will be available for highlighting code blocks.
*/
preload?: ShikiLang[]
},
/**
* Options for yaml parser.
*
* @default {}
*/
yaml: false | Record<string, any>
/**
* Options for yaml parser.
*
* @default {}
*/
csv: false | Record<string, any>
/**
* Enable/Disable navigation.
*
* @default {}
*/
navigation: false | {
fields: Array<string>
}
/**
* List of locale codes.
* This codes will be used to detect contents locale.
*
* @default []
*/
locales: Array<string>
/**
* Default locale for top level contents.
*
* @default undefined
*/
defaultLocale: string
}

When you add new options, it's better to check type definition of unjs/listhen's listen function, to which options that you are adding are supposed to be passed.

Second, you need to define the default value(s) for the options.

content/src/module.ts

Lines 181 to 197 in 8cab297

defaults: {
base: '_content',
watch: true,
sources: ['content'],
ignores: ['\\.', '-'],
locales: [],
defaultLocale: undefined,
highlight: false,
markdown: {
tags: Object.fromEntries(PROSE_TAGS.map(t => [t, `prose-${t}`]))
},
yaml: {},
csv: {},
navigation: {
fields: []
}
},

Third, as you described, change the call of listen function.

const { server, url } = await listen(() => 'Nuxt Content', { port: 4000, showURL: false })

You may need to add a unit test in test directory.

https://github.com/nuxt/content/tree/main/test


By the way, since Nuxt Content v2 have already reached to stable version, design of option schema should be well-designed for it not to be legacy (generally, no breaking change are supposed to be made while its major version is same).

You could start to develop a PR for demonstration, or might want to get feedback from the authors and other people in the community about design before creating a PR.


I will post another message if I come up with an idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants