@barelyhuman/conrou
Advanced tools
Comparing version 0.1.2-alpha.6 to 0.1.2-alpha.7
{ | ||
"name": "@barelyhuman/conrou", | ||
"version": "0.1.2-alpha.6", | ||
"version": "0.1.2-alpha.7", | ||
"repository": "git@github.com:barelyhuman/conrou.git", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -46,5 +46,9 @@ # conrou | ||
router.get('/me', 'UserController.me') | ||
// or, if you created an alias | ||
router.get('/me', 'user.me') | ||
// or | ||
router.get('/me', (req, res) => { | ||
console.log('hello') | ||
res.end() | ||
}) | ||
@@ -58,4 +62,36 @@ // to get the route for a particular controller, you can use the | ||
## Middleware | ||
Each router interface that you use might have a different way of handling middleware and so | ||
it's not really recommended to use `conrou`'s middleware utility for this. | ||
Though, conrou does provide a way for you to add in middleware that mimic the execution order similar to | ||
express. | ||
```js | ||
// Using `polka` as an example | ||
const app = polka() | ||
// Register the router as before | ||
const router = createControllerBinder(app) | ||
router.register(AuthController) | ||
router.registerMiddleware('auth', (req, res, next) => { | ||
req.currentUser = { | ||
id: 1, | ||
} | ||
next() | ||
}) | ||
router | ||
.get('/user', (req, res) => { | ||
console.log(req.currentUser) // 1 | ||
return res.end() | ||
}) | ||
// tie the named middleware to this particular route | ||
// this syntax / API was inspired by AdonisJS (https://github.com/adonisjs/) | ||
.middleware(['auth']) | ||
``` | ||
## LICENSE | ||
[MIT](/LICENSE) |
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
13089
96