routing-controllers
Advanced tools
Comparing version 0.6.0-alpha.2 to 0.6.0-alpha.3
@@ -11,4 +11,5 @@ /** | ||
}; | ||
routePrefix: string; | ||
protected processJsonError(error: any): any; | ||
protected processTextError(error: any): any; | ||
} |
@@ -9,2 +9,3 @@ "use strict"; | ||
function BaseDriver() { | ||
this.routePrefix = ''; | ||
} | ||
@@ -11,0 +12,0 @@ // ------------------------------------------------------------------------- |
@@ -28,2 +28,6 @@ import { ActionMetadata } from "../metadata/ActionMetadata"; | ||
/** | ||
* Route prefix. eg '/api' | ||
*/ | ||
routePrefix: string; | ||
/** | ||
* Registers given error handler in the driver. | ||
@@ -30,0 +34,0 @@ */ |
@@ -45,3 +45,3 @@ "use strict"; | ||
throw new BadHttpActionError_1.BadHttpActionError(action.type); | ||
this.express[expressAction](action.fullRoute, function (request, response, next) { | ||
this.express[expressAction]("" + this.routePrefix + action.fullRoute, function (request, response, next) { | ||
var options = { | ||
@@ -48,0 +48,0 @@ request: request, |
@@ -40,3 +40,3 @@ "use strict"; | ||
throw new BadHttpActionError_1.BadHttpActionError(action.type); | ||
this.router[koaAction](action.fullRoute, function (ctx, next) { | ||
this.router[koaAction]("" + this.routePrefix + action.fullRoute, function (ctx, next) { | ||
return new Promise(function (resolve, reject) { | ||
@@ -43,0 +43,0 @@ var options = { |
@@ -40,2 +40,6 @@ import { MetadataArgsStorage } from "./metadata-builder/MetadataArgsStorage"; | ||
errorOverridingMap?: Object; | ||
/** | ||
* Route prefix. eg '/api' | ||
*/ | ||
routePrefix?: string; | ||
} | ||
@@ -42,0 +46,0 @@ /** |
@@ -109,2 +109,4 @@ "use strict"; | ||
driver.errorOverridingMap = options.errorOverridingMap; | ||
if (options.routePrefix !== undefined) | ||
driver.routePrefix = options.routePrefix; | ||
// next create a controller executor | ||
@@ -111,0 +113,0 @@ new RoutingControllerExecutor_1.RoutingControllerExecutor(driver) |
{ | ||
"name": "routing-controllers", | ||
"private": false, | ||
"version": "0.6.0-alpha.2", | ||
"version": "0.6.0-alpha.3", | ||
"description": "Allows to use class-based controllers with express.js in Typescript", | ||
@@ -6,0 +6,0 @@ "license": "Apache-2.0", |
@@ -81,7 +81,7 @@ # routing-controllers | ||
import * as express from "express"; | ||
import {registerActionsInExpressApp} from "routing-controllers/routing-controllers"; | ||
import {useExpressServer} from "routing-controllers"; | ||
import "./UserController"; // we need to "load" our controller | ||
let app = express(); // create express application | ||
registerActionsInExpressApp(app); // register controllers routes in our express application | ||
useExpressServer(app); // register controllers routes in our express application | ||
app.listen(3000); // now we can run your express application. | ||
@@ -103,9 +103,36 @@ ``` | ||
import * as express from "express"; | ||
import {registerActionsInExpressApp} from "routing-controllers/routing-controllers"; | ||
import {useExpressServer} from "routing-controllers"; | ||
var controllers = require('require-all')({ | ||
dirname : __dirname + '/controllers', | ||
filter : /(.+Controller)\.js$/, | ||
excludeDirs : /^\.(git|svn)$/, | ||
recursive : true | ||
}); | ||
let app = express(); // create express application | ||
registerActionsInExpressApp(app, [__dirname + "/controllers"]); // register controllers routes in our express application | ||
useExpressServer(app); // register controllers routes in our express application | ||
app.listen(3000); // now we can run your express application. | ||
``` | ||
#### Load all controllers from the given directory and prefix routes | ||
If you want to prefix all routes in some directory eg. /api | ||
```javascript | ||
import * as express from "express"; | ||
import {useExpressServer} from "routing-controllers"; | ||
let app = express(); // create express application | ||
useExpressServer(app, { | ||
routePrefix: '/api', | ||
controllerDirs: [__dirname + "/api"] // register controllers routes in our express app | ||
}); | ||
useExpressServer(app, { | ||
routePrefix: '/auth', | ||
controllerDirs: [__dirname + "/auth"] // register controllers routes in our express app | ||
}); | ||
app.listen(3000); // now we can run your express application. | ||
``` | ||
#### Set response body value returned by a controller action | ||
@@ -112,0 +139,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
209594
3346
308