Open BurningDog opened 9 years ago
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.
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();
});
});
At https://github.com/linemanjs/lineman/issues/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 https://github.com/linemanjs/lineman/issues/318#issuecomment-62154875 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.