Describe the feature you'd like to request
tRPC has a great @trpc/server/adapters/standalone package which in theory makes it very easy to stand up an instance when learning - or a simple instance for deployment!
The simplest method in theory being:
import { createHTTPServer } from '@trpc/server/adapters/standalone'
import { appRouter } from './appRouter'
const server = createHTTPServer({
router: appRouter,
batching: {
enabled: true,
}
})
server.listen(3333)
The problem is in my experience this can't be used locally, because it doesn't respond to options requests or handle CORS, both of which browsers nowadays require.
What I actually have to write every time I want a standalone server is this, which takes a lot more research and domain knowledge:
import { createHTTPHandler } from '@trpc/server/adapters/standalone'
import { createServer } from 'http'
import { appRouter } from './appRouter'
const handler = createHTTPHandler({
router: appRouter,
batching: {
enabled: true,
},
})
const server = createServer((req, res) => {
res.setHeader('Access-Control-Allow-Origin', '*')
res.setHeader('Access-Control-Request-Method', '*')
res.setHeader('Access-Control-Allow-Methods', '*')
res.setHeader('Access-Control-Allow-Headers', '*')
if (req.method === 'OPTIONS') {
res.writeHead(200)
return res.end()
}
handler(req, res)
})
server.listen(3333)
Describe the solution you'd like to see
Add configurable support in createHTTPServer to handle Options and CORS and make local development much easier to get going. Possibly make deployment much easier too.
Describe alternate solutions
Don't do anything, this issue in itself is perfectly fine documentation in combination with #623
Additional information
No response
👨👧👦 Contributing
Describe the feature you'd like to request
tRPC has a great @trpc/server/adapters/standalone package which in theory makes it very easy to stand up an instance when learning - or a simple instance for deployment!
The simplest method in theory being:
The problem is in my experience this can't be used locally, because it doesn't respond to options requests or handle CORS, both of which browsers nowadays require.
What I actually have to write every time I want a standalone server is this, which takes a lot more research and domain knowledge:
Describe the solution you'd like to see
Add configurable support in
createHTTPServerto handle Options and CORS and make local development much easier to get going. Possibly make deployment much easier too.Describe alternate solutions
Don't do anything, this issue in itself is perfectly fine documentation in combination with #623
Additional information
No response
👨👧👦 Contributing