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

Can it run in conjunction with grunt-server on the same port? #1

Closed
adardesign opened this issue Jan 30, 2014 · 6 comments
Closed

Can it run in conjunction with grunt-server on the same port? #1

adardesign opened this issue Jan 30, 2014 · 6 comments

Comments

@adardesign
Copy link

Can it run in conjunction with grunt-server on the same port?

How would I fire it up via a gruntTask?

@ecordell
Copy link
Contributor

It can't run on the same port, but I am using grunt to manage everything.

Here's the Gruntfile I've been using. Not the prettiest but it gets the job done:

var exec = require('child_process').exec;

module.exports = function(grunt) {

  grunt.initConfig({
    concat: {
      options: {
        separator: grunt.util.linefeed,
      },
      blueprint: {
        src: ['parts/*.md'],
        filter: 'isFile',
        dest: 'blueprint.md',
      },
    },
    shell: {
      docs: {
        command: function() {
          var port = grunt.option('p') || '3002';
          var templateFile = grunt.option('t') || 'templates/flatly-multi.jade';
          var inputFile = grunt.option('i') || './blueprint.md';
          var all = grunt.option('a');
          if (all) {
            console.log('Merging blueprint...');
            grunt.task.run('concat:blueprint');
            inputFile = './blueprint.md';
          }
          return 'aglio -t ' + templateFile + ' -i ' + inputFile + ' -s' + ' -p ' + port;
        },
        options: {
          stdout: true,
          stderr: true
        }
      },
      mock: {
        command: function() {
          var port = grunt.option('p') || '3001';
          var inputFile = grunt.option('i') || './blueprint.md';
          var all = grunt.option('a');
          if (all) {
            console.log('Merging blueprint...');
            grunt.task.run('concat:blueprint');
            inputFile = './blueprint.md';
          }
          return './node_modules/api-mock/bin/api-mock ' + inputFile + ' -p ' + port;
        },
        options: {
          stdout: true,
          stderr: true
        }
      },
      test: {
        command: function() {
          var endpoint = grunt.option('e') || 'http://localhost:3001/';
          var inputFile = grunt.option('i') || './blueprint.md';
          var all = grunt.option('a');
          if (all) {
            console.log('Merging blueprint...');
            grunt.task.run('concat:blueprint');
            inputFile = './blueprint.md';
          }
          return './node_modules/dredd/bin/dredd ' + inputFile + ' ' + endpoint + ' --sorted -h Accept:application/json';
        },
        options: {
          stdout: true,
          stderr: true
        }
      }
    }
  });

  grunt.loadNpmTasks('grunt-shell');
  grunt.loadNpmTasks('grunt-contrib-concat');

  grunt.registerTask('docs', 'Launch the documentation server.', ['shell:docs']);
  grunt.registerTask('mock', 'Launch a mock server generated by the blueprint.', ['shell:mock']);
  grunt.registerTask('test', 'Run automated tests against the API.', ['shell:test']);
  grunt.registerTask('merge', 'Merge the parts of the api together.', ['concat:blueprint']);
  grunt.registerTask('default', ['docs']);

};

I was planning to make an example skeleton project of our blueprint/tooling, but here's a quick rundown:

  • The blueprint is split into parts in the /parts folder
  • I have grunt tasks for merging the parts, viewing the generated docs (with aglio), running the mock server (with api-mock), and running automated tests (with dredd)
    • Each task can also just take an individual part so that you don't have to work with the entire blueprint at a time.

The part relevant to your question is the shell:mock task, but I thought it was worth seeing a full example.

@adardesign
Copy link
Author

Thanks, But is there a way that I can fire up a developing environment sort of grunt-server and will have the mock api's work natively and not have cross-origin issues, without CORS etc.

@ecordell
Copy link
Contributor

@adardesign I may not understand your question, then. What are you trying to do?

@adardesign
Copy link
Author

Im trying to create a development environment where I can use mockAPI's easily and in the same-origin by simply firing up a grunt task which it:

  • Should act as regular grunt-server to serve the files, (live-reload etc.)
  • And also listen for the /API/ and it should serve mock data on the same port as the server, so there will not be cross-origin problems.
  • Have the watch task behave accordingly to serve the freshest API change

Thanks!

@ecordell
Copy link
Contributor

Does issue #2 and the fix, 2180316, allow you to do what you want?

@adardesign
Copy link
Author

sort of, but now need to wire grunt-contrib-connect to run via express.

Thanks!

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