-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
36 lines (27 loc) · 972 Bytes
/
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
var FS = require("q-io/fs");
var express = require('express');
var app = express();
var templateRegex = /<!--\$content\$-->/m;
var templateFile = FS.read("./index.html");
var jspm = require('jspm');
jspm.setPackagePath('.');
app.use("/render", function(req, res) {
templateFile.then(function(content) {
jspm
.import('app/app-server.jsx!')
.then(function(injectedScript) {
content = content.replace(templateRegex, injectedScript.default);
res.setHeader('Content-Type', 'text/html');
res.end(content);
}, function(err) {
res.status(500).send("Error converting template.");
});
},
function() {
res.status(500).send("Error reading template file.");
});
});
app.use(express.static('.'));
var server = app.listen(9779, function () {
console.log('Example app listening at http://localhost:%s', server.address().port);
});