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

Parameter path for import #78

Open
henri9813 opened this issue Sep 26, 2019 · 0 comments
Open

Parameter path for import #78

henri9813 opened this issue Sep 26, 2019 · 0 comments

Comments

@henri9813
Copy link

henri9813 commented Sep 26, 2019

Hello,

It could be very interesting to have the possibilites to have dynamic file import with the queried path:

Query: http://localhost:8000/articles/1

My mock file: /mocks/__/GET.mock

HTTP/1.1 200 OK
Content-Type: application/json

#import `${request.url.split('/')[2]+".json"}`;

I try this:

module.exports = (() => {
    var fs = require('fs');
    var obj = JSON.parse(fs.readFileSync("./"+request.url.split('/')[2]+".json", 'utf8'));
    return obj;
})();

But relative path doesn't work, and i'm not fan to put an absolute path here, but it works

Do you have a solution ?

Thanks for all :-)

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

1 participant