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

Global server at /api #13852

Closed
tobiasdiez opened this issue Apr 26, 2022 · 5 comments
Closed

Global server at /api #13852

tobiasdiez opened this issue Apr 26, 2022 · 5 comments

Comments

@tobiasdiez
Copy link
Contributor

Environment

  • Operating System: Linux
  • Node Version: v16.13.0
  • Nuxt Version: 3.0.0-rc.1
  • Package Manager: yarn@1.22.17
  • Builder: vite
  • User Config: target, bridge, vite, alias, nitro, ssr, meta, css, tailwindcss, modules, watch, runtimeConfig, build, storybook
  • Runtime Modules: @nuxtjs/tailwindcss@5.0.2, @pinia/nuxt@0.1.8
  • Build Modules: -

Reproduction

JabRef/JabRefOnline#1009

Describe the bug

Not sure if this is a bug report or a feature request.

For graphql servers, it's quite common to only expose a single server route. However, I was not able to expose the server at /api. I tried adding a /server/api/index.ts file, but then the server would be available at /api/index. With /server/api/[...].ts one has to use /api/ with slash.

Additional context

No response

Logs

No response

@Hungrynow666
Copy link

Environment

  • Operating System: Linux

  • Node Version: v16.13.0

  • Nuxt Version: 3.0.0-rc.1

  • Package Manager: yarn@1.22.17

  • Builder: vite

  • User Config: target, bridge, vite, alias, nitro, ssr, meta, css, tailwindcss, modules, watch, runtimeConfig, build, storybook

  • Runtime Modules: @nuxtjs/tailwindcss@5.0.2, @pinia/nuxt@0.1.8

  • Build Modules: -

Reproduction

JabRef/JabRefOnline#1009

Describe the bug

Not sure if this is a bug report or a feature request.

For graphql servers, it's quite common to only expose a single server route. However, I was not able to expose the server at /api. I tried adding a /server/api/index.ts file, but then the server would be available at /api/index. With /server/api/[...].ts one has to use /api/ with slash.

Additional context

No response

Logs

No response

@Aareksio
Copy link
Contributor

Not sure if this is a bug or a feature, but you should be able to work around it with serverMiddleware in config like so:

serverMiddleware: {
	{ path: '/api', handler: '~/server/graphql.ts' }
}

Copy link
Member

This seems to work fine for me with ~/server/api/index.ts as of the latest Nuxt/Nitro releases: https://stackblitz.com/edit/github-bgnqbx

@tobiasdiez
Copy link
Contributor Author

Thanks for the update. I can confirm that with a file at ~/server/api/index.ts the /api route works as expected. However, the route with a slash, /api/ shows now the main index page (in the above stackbliz you linked to) or a 404 error (in my repo).

@danielroe
Copy link
Member

Let's follow that request in #14892.

@danielroe danielroe added the 3.x label Jan 19, 2023
@danielroe danielroe transferred this issue from nuxt/framework Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants