Skip to content

API Routes support for express handlers #2241

Closed as not planned
Closed as not planned

Description

@jadedevin13

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

Activity

  1. jadedevin13 commented on Sep 1, 2024

    @jadedevin13
    ContributorAuthor

    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)
      },
    })
  2. SeanCassiere commented on Sep 1, 2024

    @SeanCassiere
    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

  3. SeanCassiere commented on Sep 15, 2024

    @SeanCassiere
    Member

    Closing this as there's no reproduction available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions