-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
JSONP doesn't seem to be working #822
Comments
#531 suggests that JSONP support is in hapi, but can't seem to get it to work. |
Full example:
|
There seems to be a BUG. I have it setup as such: var getUser = {
handler: function (request) {
var parts = this.params.name.split('/');
request.reply({ first: parts[0], last: parts[1] });
},
jsonp: 'callback'
};
server.route({
method: 'GET',
path: '/user/{name*2}',
config: getUser,
}); THEN I try: The EXPECTED result is: The ACTUAL result is: |
I just tried this test: var handler = function () {
var parts = this.params.name.split('/');
this.reply({ first: parts[0], last: parts[1] });
};
var server = new Hapi.Server(0);
server.route({
method: 'GET',
path: '/user/{name*2}',
config: {
handler: handler,
jsonp: 'callback'
}
});
server.start(function () {
Request(server.info.uri + '/user/1/2?callback=docall', function (err, res, body) {
expect(err).to.not.exist;
expect(body).to.equal('docall({"first":"1","last":"2"});');
expect(res.headers['content-type']).to.equal('text/javascript; charset=utf-8');
done();
});
}); And it works fine. Can you change it to reproduce the issue? |
Can you try the URL in your browser and confirm that it works that way? |
Checked your example and it works fine in node.js, but when you try and use the URL in HTML from your brower as such: |
I see it. Debugging. |
@muoto Can you try the branch? |
@hueniverse - fixed! Thank you! |
It was harder to write the test than to fix the bug... |
Just look at the tests. |
This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions. |
Does hapi support JSONP? The following doesn't work:
http://localhost:8000/hello?jsonp=mycallback
Does someone have an example of how to use hapi with JSONP?
The text was updated successfully, but these errors were encountered: