-
Notifications
You must be signed in to change notification settings - Fork 42
/
server.js
46 lines (41 loc) · 1.55 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
var connect = Npm.require("connect");
var fs = Npm.require("fs");
var path = Npm.require("path");
var Fiber = Npm.require("fibers");
WebApp.connectHandlers
.use(connect.query())
.use(function (req, res, next) {
// Need to create a Fiber since we're using synchronous http calls
Fiber(function() {
try{
var code = fs.readFileSync(path.resolve('bundle/app.html'));
}catch(e){
var code = fs.readFileSync(path.resolve('.meteor/local/build/app.html'));
}
var angular = "";
try{
angular = fs.readFileSync(path.resolve('bundle/static/angular.html'));
}catch(e){
if(fs.existsSync("public/angular.html")){
angular = fs.readFileSync(path.resolve('public/angular.html'));
}else{
console.log("Angularjs\n______\nCreate public/angular.html\n This is used as your main page, this should contain the contents of the body.");
}
}
code = new String(code);
// console.log((new String(angular)).join());
code = code.replace("<body>",new String(angular));
code = code.replace("<html##HTML_ATTRIBUTES##>",'<html ng-app="meteorapp">');
if (typeof __meteor_runtime_config__ !== 'undefined') {
code = code.replace(
"// ##RUNTIME_CONFIG##",
"__meteor_runtime_config__ = " +
JSON.stringify(__meteor_runtime_config__) + ";");
}
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(code);
res.end();
return;
//next();
}).run();
});