Allow middleware to set http status code

This commit allows middleware to set the status code of the http response. This will allow a server-side router to return, for example, a '404 Not Found' response. This has SEO benefits because currently search engines may index example.org/page-that-doesn't-exist because Meteor returns a 200 OK code and the normal boilerplate response body. With a proper 404 status we can still return the boilerplate to render a client side 404 template but search engines won't index the page. Instead of a hardcoded 200 response, we call res.writeHead with res.statusCode, and fallback to the default 200 code if it has not been set.
This commit is contained in:
Michael Mason
2016-01-05 11:05:53 +00:00
parent 4f8d7dce24
commit f263ca4fea

View File

@@ -708,7 +708,8 @@ var runWebAppServer = function () {
return undefined;
}
res.writeHead(200, headers);
var statusCode = res.statusCode ? res.statusCode : 200;
res.writeHead(statusCode, headers);
res.write(boilerplate);
res.end();
return undefined;