[nodebb-plugin-blog-comments] Unable to post topic error
-
Hi guys, running into a problem here when trying to tie the plugin into my blog and forum.
Forum is hosted at: http://www.onlyanexcuse.com
Blog is at: http://www.onlyanexcuse.com/wordpress (for now, plan to move it later but want to get this working first to test it after it went pear shaped last time).I have installed JSON API on Wordpress, plugin is installed on my forum (NodeBB v0.7.0.), Comments section has been replaced with the following:
<?php if ( post_password_required() ) return; ?> <a id="nodebb/comments"></a> <script type="text/javascript"> var nodeBBURL = 'http://www.onlyanexcuse.com', articleID = '<?php echo the_ID(); ?>'; (function() { var nbb = document.createElement('script'); nbb.type = 'text/javascript'; nbb.async = true; nbb.src = nodeBBURL + '/plugins/nodebb-plugin-blog-comments/lib/wordpress.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(nbb); })(); </script> <noscript>Please enable JavaScript to view comments</noscript>
And the settings in the plugin page on ACP are as follows:
All good so far. When I publish an article, I get a button underneath it to "Publish this article to NodeBB".
When clicked, I get this error:
{"error":"Unable to post topic"}
And this comes up in my error logs in nodebb/logs/output.log:
9/6 16:54 [5926] - [33mwarn[39m: [nodebb-plugin-blog-comments] Origin (undefined) does not match hostUrls: http://www.onlyanexcuse.com/wordpress
Could @psychobunny or anyone else see where I may be going wrong?
Additional note: In the "comments.php" file, i've used both "http://www.onlyanexcuse.com" and "//www.onlyanexcuse.com". Both produce the same result.
-
The
Origin
field seems to be not set in your servers request header.
That's whatOrigin (undefined) does...
, especially theundefined
part is telling you.Why that is, I can't tell since I'm not familiar with the plugin. Though, I doubt that this problem arises on the NodeBB side. It's rather the job of the sender (nodebb is the receiving end, here) to add that Origin field. Meaning: Your plugin seems to be set up correctly, it just isn't receiving anything to compare your set URL against.
-
Thanks @rbeer that's an avenue to persue for now. Wordpress is doing the sending, and it was set up on my server after NodeBB, and there were a few things I had to fix before I could get it working properly; it wasn't a one-click install or anything.
-
Did you figure it out? I went to your website and didn't notice any nodebb related code in the source: http://www.onlyanexcuse.com/wordpress/another-go/
-
@psychobunny I was chatting to @rbeer on here and literally just switched the theme back to twentyfifteen, which I had edited and tested with. You may have caught it just before I did that, I was playing about with different themes earlier. If you could have another look it should show up
-
Well, the requests to Google (for the fonts) e.g. do have the Origin set to your domain (http://www.onlyanexcuse.com).
Just for the kicks, you could try to add a:
XHR.setRequestHeader('Origin', 'http://www.onlyanexcuse.com');
just before the
.send()
call.This way you could rule out nginx misconfiguration. I would argue, at least, since then you know for sure, that the client is sending the correct request header.
edit: whoops - setRequestHeader, not addRequestHeader
-
If that works I can update this plugin to send that header by default
-
Thanks @rbeer, unsure exactly where to add that; is it in the Wordpress.js and if so which line?
-
@Danny-McWilliams
Yes, that's wordpress.js, Line #185. But before that, since .send() executes the request. You'll have to set it up, i.e. add headers, before calling it.But I stumbled upon something else: https://html.spec.whatwg.org/multipage/browsers.html#same-origin
Just ain't got the time to go through this. Maybe that's also of interest to you, @psychobunny. I can imagine, same-origin applies more often with this plugin. And maybe there's the difference, since e.g. blog.nodebb.org sits on another (sub-)domain, opposed to what @Danny-McWilliams is trying to do here (http://domain.com to http://domain.com/wordpress)
-
Thanks @rbeer, still no further but as you say I need to add the appropriate headers to get it working.
The site is now on the following structure:
http://www.onlyanexcuse.com - wordpress
http://forum.onlyanexcuse.com - nodebbAnd the same problem persists. As for adding the header, I think i'll need to see why Wordpress isn't and how to fix it.