Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Passing configuration to serverMiddleware in nuxt2-bridge no more possible #2705

Closed
ayalon opened this issue Jan 13, 2022 · 0 comments
Closed

Comments

@ayalon
Copy link

ayalon commented Jan 13, 2022

Environment

------------------------------
- Operating System: `Linux`
- Node Version:     `v16.13.1`
- Nuxt Version:     `2.16.0-27292334.ab1c6cb4`
- Package Manager:  `npm@8.1.2`
- Bundler:          `Webpack`
- User Config:      `head`, `css`, `plugins`, `components`, `buildModules`, `modules`, `build`, `bridge`, `typescript`, `graphqlMiddleware`, `publicRuntimeConfig`, `privateRuntimeConfig`
- Runtime Modules:  `~/modules/nuxt-graphql-middleware/src/module.ts`
- Build Modules:     `@nuxt/bridge@3.0.0-27296423.f3082ca`

Reproduction

In Nuxt 2 we added a serverMiddleware from the module like that:

  // Add the server middleware.
  this.addServerMiddleware({
    path: config.endpointNamespace,
    handler: serverMiddleware(
      config.graphqlServer,
      queries,
      mutations,
      config.server
    ),
  })

We need to pass a lot of configuration to the middleware defined in nuxt.config.ts.

Describe the bug

With Nuxt2 bridge we cannot pass a function anymore. It does not work with nitro if we pass a function. We have to pass a file path to build the standalone nitro server.

But how can we pass all the configuration settings?

There must be a way to access the nuxt configuration some how?

// middleware.ts
import { createApp } from 'h3'

const app = createApp()
app.use('/hello', () => {
  return {
    hello: 'world',
  }
})
export default app
// module.ts
  const MIDDLEWARE_PATH = path.resolve(__dirname, 'middleware.ts')

  this.addServerMiddleware({
    path: config.endpointNamespace,
    handler: MIDDLEWARE_PATH
  })

How can we somehow pass the configuration?

Additional context

No response

Logs

No response

@nuxt nuxt locked and limited conversation to collaborators Jan 14, 2022
@danielroe danielroe converted this issue into a discussion Jan 14, 2022
@danielroe danielroe added the 3.x label Jan 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants