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

API Routes support for express handlers #2241

Closed
jadedevin13 opened this issue Sep 1, 2024 · 3 comments
Closed

API Routes support for express handlers #2241

jadedevin13 opened this issue Sep 1, 2024 · 3 comments
Labels
information needed Further information is requested

Comments

@jadedevin13
Copy link
Contributor

jadedevin13 commented Sep 1, 2024

Describe the bug

Raising this as an issue because it's working before and now it's working only in dev.

I used to be able to do something like this before the tanstack start api routes were introduced

import { tusServer } from '@/server/tus-server'
import { eventHandler } from 'vinxi/http'


export default eventHandler(async (event) => {
    return tusServer.handle(event.node.req, event.node.res)
})

This is done by using the following in the app.config.ts

import { apiRouter } from '@vinxi/router/api'

This is cool because I can add middlewares for auth like.

    apiRouter({ dir: './api-ext', base: '/_api', middleware: './app/middleware/api-middleware.ts' }),

But unfortunately, when building for prod. It removed those files and instead just use the tanstack api. So I either need to use tanstack start api or use the vinxi api route which is currently have so much more features than start api provides.

Your Example Website or App

NA

Steps to Reproduce the Bug or Issue

NA

Expected behavior

NA

Screenshots or Videos

No response

Platform

NA

Additional context

No response

@jadedevin13
Copy link
Contributor Author

jadedevin13 commented Sep 1, 2024

Note that i've tried doing this but it's not working in prod build, only in dev. Specifically the PATCH method. I'm not sure why.

import { tusServer } from '@/server-only/tus-server'
import { json } from '@tanstack/start'
import { createAPIFileRoute } from '@tanstack/start/api'
import { getEvent } from 'vinxi/http'

export const Route = createAPIFileRoute('/api/tus/$file')({
  GET: ({ request, params }) => {
    const event = getEvent()
    return tusServer.handle(event.node.req, event.node.res)
  },
  POST: ({ request, params }) => {
    const event = getEvent()
    return tusServer.handle(event.node.req, event.node.res)
  },
  PATCH: ({ request, params }) => {
    const event = getEvent()
    return tusServer.handle(event.node.req, event.node.res)
  },
  PUT: ({ request, params }) => {
    const event = getEvent()
    return tusServer.handle(event.node.req, event.node.res)
  },
  OPTIONS: ({ request, params }) => {
    const event = getEvent()
    return tusServer.handle(event.node.req, event.node.res)
  },
})

@SeanCassiere
Copy link
Member

@jadedevin13 please make sure you provide a reproduction/a minimal example when filing an issue.
Without it, we are unable to try out the problem and find a suitable solution (especially in this scenario, where it is setup dependant).

If you are using Router, you can create a reproduction using this Stackblitz starter: https://stackblitz.com/github/tanstack/router/tree/main/examples/react/quickstart-file-based?preset=node&file=src/main.tsx
If you are using Start, you can create a reproduction using: https://stackblitz.com/github/tanstack/router/tree/main/examples/react/start-basic?preset=node&file=src/main.tsx

@SeanCassiere SeanCassiere added the information needed Further information is requested label Sep 1, 2024
@SeanCassiere
Copy link
Member

Closing this as there's no reproduction available.

@SeanCassiere SeanCassiere closed this as not planned Won't fix, can't repro, duplicate, stale Sep 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
information needed Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants