Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Dyson - Cannot GET /dummy #6

Closed
jessecravens opened this issue Feb 9, 2013 · 5 comments
Closed

Dyson - Cannot GET /dummy #6

jessecravens opened this issue Feb 9, 2013 · 5 comments

Comments

@jessecravens
Copy link

First off ... great project. I'd like to start using dyson for faking json data in my prototypes, but I am missing something in what should be a simple workflow.

It may very well be user error .. but Ive installed globally, and can run demo just fine.
I can init directories in my current projects, and even fire up dyson - to receive:

Dyson listening at port 3000

When I hit localhost:3000/dummy
or whatever config objects Ive placed in the directory, I get:

Cannot GET /dummy

with no exceptions thrown. Quiet console.

I'm going to dig in and figure this out, but thought Id log this for others and/or if you may know off the top of your head what I might be missing.

@webpro
Copy link
Owner

webpro commented Feb 10, 2013

Thanks for trying out dyson.

Let me try to describe how I meant this to work:

  1. The "init" command creates e.g. /myApp/configs/get/dummy.js.
  2. Then from within the myApp directory, dyson should be started with dyson configs/

Dyson also sends the registered services to the console on boot (just like the demo), so if there's only "Dyson listening" then it didn't find any configs.

So what might went wrong in your situation is starting dyson with the [dir] argument (containing the method config directories).

But of course there can also be a bug in dyson, which I would really care to know about.

@jessecravens
Copy link
Author

Well, looks like loader is not overriding the defaults in load():

['get', 'post', 'put', 'delete'].forEach(function(method) {
    methodDir = configDir + '/' + method;
    methodConfigs = _.flatten(requireDir(methodDir), true);
    console.log(methodConfigs)
    configs[method] = defaults.assign(methodConfigs, method);
});

returns 4 empty arrays:

[]
[]
[]
[]

In requireDir(),

it returns on the first conditional: if(!(fs.existsSync(dir) && fs.statSync(dir).isDirectory())) return;

UPDATE:

I think it is actually working as designed when I run dyson configs/ from within my app directory.
I wasn't initially including the trailing slash, then I was trying 'configs', '/configs,' and 'configs/' and comparing the results.

So, when using 'configs/' , it is erroring on var g = require('dyson').generators from within get/dummy.js.

module.js:340
throw err;
^
Error: Cannot find module 'dyson'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at Object. (/Users/jesse.cravens/Code/static_projects/sp-static/configs/get/dummy.js:1:71)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:362:17)

So, my app is not a node app. It is just a static ember.js application for now, but I would think that since dyson is installed globally, that require('dyson') would still resolve.

So by hardcoding the dependencies (dyson and lodash) back to the global directories:
/Users/username/nvm/v0.8.14/lib/node_modules/dyson/lib/dyson
/Users/username/nvm/v0.8.14/lib/node_modules/dyson/node_modules/lodash/lodash

everything works.

@webpro
Copy link
Owner

webpro commented Feb 11, 2013

That is mentioned, yet briefly, in the README:

To use the data generators, dyson needs to be added to the devDependencies.

So you would need to add a package.json and make it a Node project, e.g.:

{
    "name": "myProject",
    "version" : "0.0.1",
    "dependencies": {},
    "devDependencies": {
        "dyson": "0.0.4",
    }
}

And then npm install. I will think about a better way when I get to it. As you found out, like me before (#2), requiring the global dyson doesn't work.

@jessecravens
Copy link
Author

Ok ... make sense. Thanks a bunch.

@webpro
Copy link
Owner

webpro commented Feb 13, 2013

OK, I hope things are working out for you now. I updated the README with a note, and you can now include dyson-generators (instead of ('dyson').generators), as can be found in the examples in both projects.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants