mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
@@ -649,81 +649,83 @@ var runWebAppServer = function () {
|
||||
});
|
||||
|
||||
app.use(function (req, res, next) {
|
||||
if (! appUrl(req.url))
|
||||
return next();
|
||||
Fiber(function () {
|
||||
if (!appUrl(req.url))
|
||||
return next();
|
||||
|
||||
var headers = {
|
||||
'Content-Type': 'text/html; charset=utf-8'
|
||||
};
|
||||
if (shuttingDown)
|
||||
headers['Connection'] = 'Close';
|
||||
var headers = {
|
||||
'Content-Type': 'text/html; charset=utf-8'
|
||||
};
|
||||
if (shuttingDown)
|
||||
headers['Connection'] = 'Close';
|
||||
|
||||
var request = WebApp.categorizeRequest(req);
|
||||
var request = WebApp.categorizeRequest(req);
|
||||
|
||||
if (request.url.query && request.url.query['meteor_css_resource']) {
|
||||
// In this case, we're requesting a CSS resource in the meteor-specific
|
||||
// way, but we don't have it. Serve a static css file that indicates that
|
||||
// we didn't have it, so we can detect that and refresh. Make sure
|
||||
// that any proxies or CDNs don't cache this error! (Normally proxies
|
||||
// or CDNs are smart enough not to cache error pages, but in order to
|
||||
// make this hack work, we need to return the CSS file as a 200, which
|
||||
// would otherwise be cached.)
|
||||
headers['Content-Type'] = 'text/css; charset=utf-8';
|
||||
headers['Cache-Control'] = 'no-cache';
|
||||
res.writeHead(200, headers);
|
||||
res.write(".meteor-css-not-found-error { width: 0px;}");
|
||||
if (request.url.query && request.url.query['meteor_css_resource']) {
|
||||
// In this case, we're requesting a CSS resource in the meteor-specific
|
||||
// way, but we don't have it. Serve a static css file that indicates that
|
||||
// we didn't have it, so we can detect that and refresh. Make sure
|
||||
// that any proxies or CDNs don't cache this error! (Normally proxies
|
||||
// or CDNs are smart enough not to cache error pages, but in order to
|
||||
// make this hack work, we need to return the CSS file as a 200, which
|
||||
// would otherwise be cached.)
|
||||
headers['Content-Type'] = 'text/css; charset=utf-8';
|
||||
headers['Cache-Control'] = 'no-cache';
|
||||
res.writeHead(200, headers);
|
||||
res.write(".meteor-css-not-found-error { width: 0px;}");
|
||||
res.end();
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (request.url.query && request.url.query['meteor_js_resource']) {
|
||||
// Similarly, we're requesting a JS resource that we don't have.
|
||||
// Serve an uncached 404. (We can't use the same hack we use for CSS,
|
||||
// because actually acting on that hack requires us to have the JS
|
||||
// already!)
|
||||
headers['Cache-Control'] = 'no-cache';
|
||||
res.writeHead(404, headers);
|
||||
res.end("404 Not Found");
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (request.url.query && request.url.query['meteor_dont_serve_index']) {
|
||||
// When downloading files during a Cordova hot code push, we need
|
||||
// to detect if a file is not available instead of inadvertently
|
||||
// downloading the default index page.
|
||||
// So similar to the situation above, we serve an uncached 404.
|
||||
headers['Cache-Control'] = 'no-cache';
|
||||
res.writeHead(404, headers);
|
||||
res.end("404 Not Found");
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// /packages/asdfsad ... /__cordova/dafsdf.js
|
||||
var pathname = parseurl(req).pathname;
|
||||
var archKey = pathname.split('/')[1];
|
||||
var archKeyCleaned = 'web.' + archKey.replace(/^__/, '');
|
||||
|
||||
if (!/^__/.test(archKey) || !_.has(archPath, archKeyCleaned)) {
|
||||
archKey = WebApp.defaultArch;
|
||||
} else {
|
||||
archKey = archKeyCleaned;
|
||||
}
|
||||
|
||||
var boilerplate;
|
||||
try {
|
||||
boilerplate = getBoilerplate(request, archKey);
|
||||
} catch (e) {
|
||||
Log.error("Error running template: " + e);
|
||||
res.writeHead(500, headers);
|
||||
res.end();
|
||||
return undefined;
|
||||
}
|
||||
|
||||
var statusCode = res.statusCode ? res.statusCode : 200;
|
||||
res.writeHead(statusCode, headers);
|
||||
res.write(boilerplate);
|
||||
res.end();
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (request.url.query && request.url.query['meteor_js_resource']) {
|
||||
// Similarly, we're requesting a JS resource that we don't have.
|
||||
// Serve an uncached 404. (We can't use the same hack we use for CSS,
|
||||
// because actually acting on that hack requires us to have the JS
|
||||
// already!)
|
||||
headers['Cache-Control'] = 'no-cache';
|
||||
res.writeHead(404, headers);
|
||||
res.end("404 Not Found");
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (request.url.query && request.url.query['meteor_dont_serve_index']) {
|
||||
// When downloading files during a Cordova hot code push, we need
|
||||
// to detect if a file is not available instead of inadvertently
|
||||
// downloading the default index page.
|
||||
// So similar to the situation above, we serve an uncached 404.
|
||||
headers['Cache-Control'] = 'no-cache';
|
||||
res.writeHead(404, headers);
|
||||
res.end("404 Not Found");
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// /packages/asdfsad ... /__cordova/dafsdf.js
|
||||
var pathname = parseurl(req).pathname;
|
||||
var archKey = pathname.split('/')[1];
|
||||
var archKeyCleaned = 'web.' + archKey.replace(/^__/, '');
|
||||
|
||||
if (! /^__/.test(archKey) || ! _.has(archPath, archKeyCleaned)) {
|
||||
archKey = WebApp.defaultArch;
|
||||
} else {
|
||||
archKey = archKeyCleaned;
|
||||
}
|
||||
|
||||
var boilerplate;
|
||||
try {
|
||||
boilerplate = getBoilerplate(request, archKey);
|
||||
} catch (e) {
|
||||
Log.error("Error running template: " + e);
|
||||
res.writeHead(500, headers);
|
||||
res.end();
|
||||
return undefined;
|
||||
}
|
||||
|
||||
var statusCode = res.statusCode ? res.statusCode : 200;
|
||||
res.writeHead(statusCode, headers);
|
||||
res.write(boilerplate);
|
||||
res.end();
|
||||
return undefined;
|
||||
}).run();
|
||||
});
|
||||
|
||||
// Return 404 by default, if no other handlers serve this URL.
|
||||
|
||||
Reference in New Issue
Block a user