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

Watching API stub files folder #380

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

BurningDog
Copy link

At #318 it's suggested to use the config/stubs folder for API stub files. I think this is a good suggestion and am using this for a local project.

@davemo noted at #318 (comment) that "The most annoying part of working in this way is having to restart lineman when a stubbed file changes."

This pull request solves that issue - an API file can be edited and is immediately available via Express.

@davemo
Copy link
Member

davemo commented Oct 2, 2015

This seems ok, I guess I wonder what happens if there are no files in config/stubs and if this breaks when you end up with n files and delete them to get to no files. We've seen some weirdness with the file watching happen in those scenarios before, so if you can verify nothing breaks in that case with this code change I'd be ok with this change.

@BurningDog
Copy link
Author

No files in config/stubs

Lineman starts up as normal; no warnings printed.

Having n files then deleting to get no files

After deleting my API files then doing a GET on a previously working stub, I get a "Not found" returned by Express but nothing breaks. In server.js I have:

app.get('/api/1.0/goals', function (req, res) {
      fs.readFile('config/stubs/1.0/goals.json', function(err, data) {
        if (err) {
          res.status(404).send('Not found');
        } else {
          res.header('Cache-Control', 'none').contentType('application/json').send(data);
        }
        res.end();
      });
    });

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

Successfully merging this pull request may close these issues.

3 participants