been trying to play with sails framework as planning to port my express app. The problem I got into was how to make express-device npm package to work with it. In express app I just require module like in this case var device = require('express-device') and then configure it in server.configure. Any help?
相关问题
- npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fs
- google-drive can't get push notifications
- How to reimport module with ES6 import
- Why is `node.js` dying when called from inside pyt
- How to verify laravel passport api token in node /
相关文章
- node连接远程oracle报错
- How can make folder with Firebase Cloud Functions
- @angular-cli install fails with deprecated request
- node.js modify file data stream?
- How to resolve hostname to an ip address in node j
- Transactionally writing files in Node.js
- Log to node console or debug during webpack build
- Get file created date in node
It took me a bit of looking at the Sails middleware documentation (http://sailsjs.org/documentation/concepts/middleware) to figure this out, but it ends up being a little easier than the previous answer.
In
config/http.js
, you'll want to add the following bits of code:This will get the same result as the previous answer of having
req.device
available on every request.Ok, so I found the solution... After running npm install express-device --save I had to create a express.js module inside of config/ dir and the content of module looks like this:
so now in each controller I can find the type of device that request is coming from if I need to:
Maybe there's some more clever ways to do this but this works fine for me :)