Comments (9)
Never mind, i've read this and answered my self
http://greim.github.io/hoxy/#request-json
from hoxy.
Okey !!!
I've seen that the .JSON only works with 'request' phase. So how could I respond selectively different data based on a condition that uses the body (req.json) ?
from hoxy.
Yup, I've edited the title so it's more accurate.
from hoxy.
If I understand the question, you'd just use if (req.json.something...)
somewhere in the intercept handler.
from hoxy.
Because I need the servers answer. I'm trying:
a) to extend servers API. For example, if req.json.extend === true
then _.assign(resp.json, { more: true })
so i can finally ) When incoming request, answer a stored (in mongo) version of it ( aka cached ), then continue the request so I can update that stored value with the newest server response
_.assign is the new alias for old _.extend in lodash.
from hoxy.
proxy.intercept({
phase: 'request',
as: 'json'
}, function(req, resp) {
var a;
var requestHash = {
url: req.url,
method: req.method,
headers: req.headers,
body: req.json
};
_.assign(resp.json, {extende: true}); // <- Response isn't being extende, on this phase
console.log('Check for JSON -> ', req.json.nickname);
console.log('Respond default extende ->', resp.json);
});
proxy.intercept({
phase: 'response',
as: 'json'
}, function(req, resp) {
var a;
var requestHash = {
url: req.url,
method: req.method,
headers: req.headers,
body: req.json
};
// _.assign(resp.json, {extende: true}); // <- Response here does extends here, but I've got undefined on req.json
console.log('Store the value of original -> ', req.json.nickname);
console.log('With this data, not extended', resp.json);
});
from hoxy.
You could assign response.json = { ... }
during the request phase, but be warned it will suppress the call to the server. http://greim.github.io/hoxy/#response-population
If that isn't what you want, check out this: http://greim.github.io/hoxy/#cycle-data
It would allow you to pass a value from the request to the response cycle which should get you where you need.
from hoxy.
Thanks !! I'll give it a try, and tell you later ;)
from hoxy.
That did the trick !!! Thanks a lot !!!!
from hoxy.
Related Issues (20)
- How to change files stored by cycle.serve HOT 1
- Cannot read property 'port' of null HOT 1
- retrieving ISO-8859-1 webpage encoding problem
- 304 responses fail with as:'json' interceptor HOT 3
- staticServer in Cycle is never being closed.
- Not working with HTTPS HOT 1
- Ignore SSL HOT 1
- Drop Requests
- New maintained Proxy Library
- Proxy Server crashing
- Question: Change target of reverse proxy depending on situation HOT 5
- https with upstream proxy HOT 3
- Hoxy is preventing Node from exiting HOT 2
- Promises don't seem to work alongside interception handlers at all HOT 1
- question HOT 2
- has Filter assignment domain?
- Missing [missing_subjectAltName] in ssl certificate in Chrome 58
- How to proxy multiple subdomains HOT 4
- certAuthority filter option
- Port added even if not necessary (http:80 / https:443) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hoxy.