Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

Possibility to add middleware(s) before the function that will generate the route for that path? #5

Closed
jy95 opened this issue Mar 3, 2017 · 0 comments

Comments

@jy95
Copy link

jy95 commented Mar 3, 2017

Hello,

I just wonder if there is not a possibility to add middleware(s) just before the handler function ...

I tried to mix the 2 osprey middlewares : https://github.com/mulesoft-labs/osprey-resources and https://github.com/mulesoft-labs/osprey-method-handler .
It doesn't seem to work together ..

I was thinking about something like that :

var express = require('express');
var resources = require('osprey-resources');
var app = express();
var handler = require('osprey-method-handler')
var connect = require('connect');

var router = resources(
  [{
    relativeUri: '/users',
    methods: [{
      method: 'post',
      body: {
        'application/json': {
          schema: '...'
        }
      }
    }]
  }],
function (method, path) {
      // the middleware(s)
      var chain = connect();
      var methodType = method.method.toUpperCase();
      chain.use(handler(method, path, methodType, {}))
      return chain;
 },
  function (method, path) {
    return function (req, res, next) {
      // the route
      res.end('hello, world!')
    }
  }
);

app.use('/v1' , router);

So, any idea ?

@jy95 jy95 closed this as completed Mar 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant