'Need to call Express like use route using Restify
Expresss.use() accepts 2 parameters
app.use('/abcd', routeHandler);
Restify only supports one
restify.use(routeHandler);
Referring to workaround on https://github.com/restify/node-restify/issues/289
server.use(scopeMiddlewareTo('/prefix', myMiddleware));
I'm trying to use this workaround, but getting below error
{"code":"InternalError","message":"middleware.call is not a function"}
I'm using Typescript, but even the JS code while debugging and middleware.call() is not found.
Basically I have routes in separate files and do not wish to use restify.get(), restify.post() in main.ts. The separate files act as sub-apps.
Solution 1:[1]
You can use this package https://www.npmjs.com/package/restify-prefix-route.
var applyPrefix = require('restify-prefix-route');
server.pre(applyPrefix('/v1'));
use this to add prefix in all routes.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | filippo |
