Arvind Singh
Arvind Singh

Reputation: 792

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.

Upvotes: 1

Views: 845

Answers (1)

abhikk
abhikk

Reputation: 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.

Upvotes: 0

Related Questions