Skip to content

Commit 0c8496a

Browse files
committed
Don't rely on client Accept headers
- Use ``WebApp.connectHandlers`` in stead of ``WebApp.rawConnectHandlers`` so that the handler runs after static middleware. Meteor doesn't document this, but source is here: https://github.com/meteor/meteor/blob/a0162f27ecc9129e732421ea0849e8dc6c52e75b/packages/webapp/webapp_server.js - Remove check for ``html`` in client accept header. - Check that the string begins with ``<!DOCTYPE html>`` before injecting. Fixes issue #4.
1 parent 11a3c5c commit 0c8496a

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

lib/server.jsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ function IsAppUrl(req) {
1919
if(RoutePolicy.classify(url)) {
2020
return false;
2121
}
22-
23-
// we only need to support HTML pages only
24-
// this is a check to do it
25-
return /html/.test(req.headers['accept']);
22+
return true;
2623
}
2724

2825
const {Router} = ReactRouter;
@@ -43,7 +40,7 @@ ReactRouterSSR.Run = function(routes, clientOptions, serverOptions) {
4340
// Parse cookies for the login token
4441
WebApp.rawConnectHandlers.use(cookieParser());
4542

46-
WebApp.rawConnectHandlers.use(Meteor.bindEnvironment(function(req, res, next) {
43+
WebApp.connectHandlers.use(Meteor.bindEnvironment(function(req, res, next) {
4744
if (!IsAppUrl(req)) {
4845
next();
4946
return;
@@ -91,7 +88,7 @@ ReactRouterSSR.Run = function(routes, clientOptions, serverOptions) {
9188

9289
var originalWrite = res.write;
9390
res.write = function(data) {
94-
if(typeof data === 'string') {
91+
if(typeof data === 'string' && data.indexOf('<!DOCTYPE html>') === 0) {
9592
data = data.replace('<body>', '<body><div id="' + (clientOptions.rootElement || 'react-app') + '">' + html + '</div>');
9693
}
9794

0 commit comments

Comments
 (0)