-
I'm trying to serve two related APIs (distinguished by two distinct top-level prefixes in their routes), generating two separate swagger docs with respective endpoints via swaggerUi.serveFiles, from one express-zod-api app. Can multiple routes (which then requires multiple configs for different tags) be used in one express-zod-api app? Normally the server and port are specified to createConfig, the resulting config used to create tagged endpoints, which are used to form routes, then those config and routes are passed to createServer. If multiple configs and routes are created, instead of calling createServer which takes only one set of config and routes, I could create app = express(). Or perhaps {app} = await createServer on one of the config/route sets, or an empty config/route. Then use attachRouting for the remaining or each of the configs and routes. Unfortunately, that doesn't seem to work because attachRouting apparently doesn't parse request.body for the input to the handlers, failing input validation based to zod types. I see the note in Connect to your own express app about "you probably need to parse request.body". Perhaps that requires middleware, but was hoping not to increase the complexity by adding this addition route set. Even if I disabled by validation by using an empty z.object({}), it's not clear how to access the request from the endpoint handler function args. Is there any way to serve two routes using besides using attachRouting? If attachRouting is my only option, what's the best way to at least get the body input (even if not validated) to the handler function? Thanks for any ideas or thoughts or alternative on this - really liking express-zod-api! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
Hello, @lpw
Could you please clarify: are those APIs listening to the same port?
Could you please clarify the differences of those two configs? If the only difference is tags, I could suggest to:
Yes, it does not. It's intended for the DIY solutions. |
Beta Was this translation helpful? Give feedback.
-
Check this out, @lpw : Would you be interested in helping me to test this feature? |
Beta Was this translation helpful? Give feedback.
-
Just pulled v16.7.0-beta1 and tested - works great! Nicely designed, keeping it in the server spec of createConfig. I'll keep testing, let me know how else I can help. Again, awesome work, thank you very much. I didn't see a place to approve the PR, not that's my approval is needed, but I'll leave an approving and grateful comment. You're quick attention to issues and actions to improve and enhance makes express-zod-api great to work with. Thanks Robin! |
Beta Was this translation helpful? Give feedback.
Hello, @lpw
Could you please clarify: are those APIs listening to the same port?
What is the nature of those prefixes? Is it a version like
v1
andv2
?Could you please clarify the differences of those two configs?
Do they only have different tags?
If the only difference is tags, I could suggest to:
const tagsV1 = {}, tagsV2 = {}, tags = {...tagsV1, ...tagsV2}
;routingV1, routingV2, routing
in a similar way;createServer()
withrouting
and sin…