Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using interfake as middleware for connect #6

Open
MartinKnopf opened this issue Mar 19, 2014 · 4 comments
Open

Using interfake as middleware for connect #6

MartinKnopf opened this issue Mar 19, 2014 · 4 comments

Comments

@MartinKnopf
Copy link

It would be nice to use interfake in a Grunt setup as a connect middleware like this:

  connect: {
    options: {
      port: 8080,
      hostname: 'localhost'
    },
    test: {
      options: {
        middleware: function (connect) {
          return [
            myInterfakeInstance.asMiddleware()
          ];
        }
      }
    }
  },
@basicallydan
Copy link
Owner

To clarify, are you imagining the interfake instance being completely set up as part of your gruntfile and then used as part of the test environment? Or rather, providing the interfake methods as part of the test environment?

@MartinKnopf
Copy link
Author

Hi,

your first idea is what I mean. I'm using grunt-contrib-connect to serve frontends on my local machine. I would like a connect middleware to fake REST APIs but I don't want to configure interfake inside the Gruntfile (since this tends to get big).

Let me add to my previous code sample:

myInterfakeInstance.js

var Interfake = require('Interfake')
  , interfake = new Interfake();

interfake.createRoute({...});

module.exports = interfake;

Gruntfile.js

connect: {
    options: {
      port: 8080,
      hostname: 'localhost'
    },
    test: {
      options: {
        middleware: function (connect) {
          return [
            require('./myInterfakeInstance').asMiddleware()
          ];
        }
      }
    }
  },

@basicallydan
Copy link
Owner

Ah, I see. Okay, I'll look into this at some point if someone doesn't get here first - I imagine it's not too hard to do. I suppose there are some hooks so that we can start and then stop the server at the appropriate moments?

@MartinKnopf
Copy link
Author

Cool!

The connect server can be started with Grunt:

grunt.registerTask('devserver', ['connect:server:keepalive']);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants