Skip to content

feat(collection): "server only" #3739

@hareland

Description

@hareland

It would be nice with "server only" collections, this would expand the usage area of nuxt content from data that will be public, to having a super basic lookup for things that would be considered "sensitive" outside the environment it is running in / db context.

Describe the solution you'd like

e.g: a way to simply include or exclude (include by default maybe?) in either client or server environment.

export default defineContentConfig({
  collections: defineCollection({
    server: boolean,
    client: boolean
  })
})

Describe alternatives you've considered

An alternative could be a nuxt hook to filter collections nuxt:content:[client|server]: (collections[]) => collections[]

A simple example use-case would be for a simple site where you define some forms with a contact person with yml/md content, but you do not want to include the email field in the public bundle, so you end up coding in variable replacement for some fields in the content/ folder.
This would allow you to have a "persons" or whatever collection that is secret, and you can simply reference that path in your form instead.

Would be happy to be pointed in the direction to how this could be achieved without the change in nuxt-content too, but as of now it would require either the config or hook option afaik.

What would be some considerations to come up with a solution for this to work properly without breaking support?

Would it be as simple as not bundling sqldump + not typing the collection in certain exports?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions