Subramanya Sastry has submitted this change and it was merged.
Change subject: Allow localsettings.js to enable CORS requests.
......................................................................
Allow localsettings.js to enable CORS requests.
CORS requests allow external apps (like Nell's Wikipedia) to use the
parsoid service.
Change-Id: I43576cabad79985ea4cf1d2da6c2e25f30dddd48
---
M js/api/ParserService.js
M js/api/localsettings.js.example
2 files changed, 18 insertions(+), 1 deletion(-)
Approvals:
Subramanya Sastry: Verified; Looks good to me, approved
diff --git a/js/api/ParserService.js b/js/api/ParserService.js
index a4dd1e6..911f688 100644
--- a/js/api/ParserService.js
+++ b/js/api/ParserService.js
@@ -440,13 +440,19 @@
}
res.end('');
});
+ if (env.conf.parsoid.allowCORS) {
+ // allow cross-domain requests (CORS) so that parsoid
service
+ // can be used by third-party sites
+ res.setHeader('Access-Control-Allow-Origin',
+ env.conf.parsoid.allowCORS);
+ }
try {
- res.setHeader('Content-Type', 'text/html;
charset=UTF-8');
console.log('starting parsing of ' + req.params[0]);
// FIXME: This does not handle includes or templates
correctly
env.page.src = src;
parser.process( src );
} catch (e) {
+ res.setHeader('Content-Type', 'text/plain;
charset=UTF-8');
console.error( e.stack || e.toString() );
res.send( e.stack || e.toString(), 500 );
}
@@ -552,8 +558,16 @@
if ( req.query.cache ) {
res.setHeader('Cache-Control', 's-maxage=2592000');
}
+ if (env.conf.parsoid.allowCORS) {
+ // allow cross-domain requests (CORS) so that parsoid
service
+ // can be used by third-party sites
+ res.setHeader('Access-Control-Allow-Origin',
+ env.conf.parsoid.allowCORS);
+ }
+
var tpr = new TemplateRequest( env, target, oldid );
tpr.once('src', parse.bind( null, env, req, res, function (
req, res, src, doc ) {
+ res.setHeader('Content-Type', 'text/html;
charset=UTF-8');
res.end(Util.serializeNode(doc.documentElement));
var et = new Date();
console.warn("completed parsing of " + target + " in "
+ (et - st) + " ms");
diff --git a/js/api/localsettings.js.example b/js/api/localsettings.js.example
index 3b0479a..98a206f 100644
--- a/js/api/localsettings.js.example
+++ b/js/api/localsettings.js.example
@@ -15,5 +15,8 @@
// Use selective serialization (default false)
//parsoidConfig.useSelser = true;
+
+ // allow cross-domain requests to the API (default disallowed)
+ //parsoidConfig.allowCORS = '*';
};
--
To view, visit https://gerrit.wikimedia.org/r/57399
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I43576cabad79985ea4cf1d2da6c2e25f30dddd48
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Parsoid
Gerrit-Branch: master
Gerrit-Owner: Cscott <[email protected]>
Gerrit-Reviewer: GWicke <[email protected]>
Gerrit-Reviewer: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits