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

I can't keep him running with my node server #1

Closed
snyoz opened this issue Jun 17, 2014 · 12 comments
Closed

I can't keep him running with my node server #1

snyoz opened this issue Jun 17, 2014 · 12 comments

Comments

@snyoz
Copy link

snyoz commented Jun 17, 2014

How Can I start the task on watch with my node?
Which port I have to choose in my config.json?

When I do: $ grunt apimocker it starts successfully. But after it the task stops.

I would be very thankful for your help.
I followed all your instructions but it doesnt work.

Kind regards,
Kevin

@gstroup
Copy link
Owner

gstroup commented Jun 18, 2014

Hi Kevin,

Sorry, I didn't get a chance to look at this yet. The task should just start up the apimocker server... The task will stop, but the server should keep running. I'll take a look at it and get back to you.

Thanks.

-Greg

On Jun 17, 2014, at 7:52 AM, snyoz notifications@github.com wrote:

How Can I start the task on watch with my node?
Which port I have to choose in my config.json?

When I do: $ grunt apimocker it starts successfully. But after it the task stops.

I would be very thankful for your help.
I followed all your instructions but it doesnt work.

Kind regards,
Kevin


Reply to this email directly or view it on GitHub.

@snyoz
Copy link
Author

snyoz commented Jun 19, 2014

Hi Greg,

thanks for your fast answer. It would be very nice if you take a look.
I have to say that you have done a great work! :)

It would be also very great if you could help me with this question:
gstroup/apimocker#8

Kind regards

@gstroup
Copy link
Owner

gstroup commented Jun 20, 2014

Hi,

I added a new sample-project-gruntfile.js to this github project for documentation. I hope this helps you. I used it for testing out the grunt-apimocker task. You can see around line 315, that I run apimocker as part of the 'serve' grunt task, not as part of the 'watch' task. Does this do what you need? The 'watch' task doesn't really make sense for apimocker… since you don't want to start the apimocker server whenever you make a change in your app. Right? If you do want it to run as part of the 'watch' task, can you explain your use case? Thanks.

-Greg


grunt.registerTask('serve', function (target) {
    if (target === 'dist') {
        return grunt.task.run(['build', 'connect:dist:keepalive']);
    }

    grunt.task.run([
        'apimocker',
        'clean:server',
        'concurrent:server',
        'autoprefixer',
        'connect:livereload',
        'watch'
    ]);
});

@gstroup
Copy link
Owner

gstroup commented Jun 22, 2014

@snyoz Please let me know if my last comment helped solve your problem, or if you need something else. Thanks.

-Greg

@kevinoconnor7
Copy link

I can also confirm that the server does not stay up once the task completes. Running apimocker path_to_config shows everything running okay and the server stays up. Using grunt apimocker shows the correct startup to get the server listening but then the task completes and the server is no longer running.

@snyoz
Copy link
Author

snyoz commented Jun 25, 2014

Hi Greg,

it was perfectly for me! Great!
Really good work, thank you!

The only thing I added additionally was:
(maybe it helps @kevinoconnor7 )

// Enable API MOCKER
        apimocker: {
            options: {
              configFile: 'node_modules/grunt-apimocker/node_modules/apimocker/config.json'
            }
        },

and to watch the JSON Mocks:

// Watches files for changes and runs tasks based on the changed files
        watch: {
            apimocker: {
                files: ['node_modules/grunt-apimocker/node_modules/apimocker/mocks/{,*/}*.json']
            },
         },

Kind regards

@gstroup
Copy link
Owner

gstroup commented Jul 10, 2014

@kevinoconnor7 Did you get this working yet? Hopefully the comments in this thread were helpful for you. If you still have issues, let me know.

@themocs
Copy link

themocs commented Jul 22, 2015

Hi @gstroup.. im traying to use this grunt no global, but server never starts, tested with this configs but doesn't keep alive. Any solution to this?

Command: grunt apimocker
Output:
Running "apimocker" task
Starting apimocker server
Loading config file: ..../node_modules/grunt-apimocker/node_modules/apimocker/test/test-config.json
Set route: GET first : king.json
Mock server listening on port 7879

Done, without errors.

@gstroup
Copy link
Owner

gstroup commented Jul 23, 2015

I think the problem is that the apimocker server will only stay up and running as long as another grunt task keeps the process up and running. If you run apimocker in your grunt 'serve' task, along with a web server like express, then the apimocker server process should remain up and running. Can you try that?

(This is an issue that we need to fix in this grunt-apimocker plugin project, but I haven't had time to work on it. Pull requests welcome!)

@moro-programmer
Copy link
Contributor

Hi Greg, thank you for your plugin. It seems to me that you can fix it just adding this.async() at the end of the tasks/apimocker.js file

like this

 grunt.log.writeln('Starting apimocker server');    
    var mocker = require('apimocker'),
        mockServer = mocker.createServer().setConfigFile(options.configFile);
        mockServer.stop().start();
    this.async();
 }

But if you do this, all previous configs will be broken. If you want, I can add an optional parameter and send you a pull request.

@gstroup
Copy link
Owner

gstroup commented Sep 4, 2015

@moro-programmer, I think you have a good idea. But why would it break all previous configs? Sorry, I have not given much attention to this plugin. If you are able to make a pull request, that would be great! I will get it merged in pretty quickly. Thanks a lot.

@moro-programmer
Copy link
Contributor

Hi. All previous configs can be broken because the next task waits apimocker. But I have added the wait parameter with default state "false". If you set it true, then the apimocker will not exit. I have sent you the pull request.

@gstroup gstroup mentioned this issue Sep 8, 2015
@gstroup gstroup closed this as completed Sep 8, 2015
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

5 participants