-
Notifications
You must be signed in to change notification settings - Fork 13.5k
/
app.js
55 lines (44 loc) · 1.13 KB
/
app.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
47
48
49
50
51
52
53
54
55
var express = require('express');
var app = express();
var fs = require('fs');
var path = require('path');
console.log(path.join(__dirname, '../../dist/'))
var stencil = require('@stencil/core');
var renderer = stencil.createRenderer({
rootDir: path.join(__dirname, '../../'),
buildDir: path.join(__dirname, '../../dist/'),
namespace: 'Ionic',
logLevel: 'debug'
});
app.get('/', function (req, res, next) {
console.log(`serve: ${req.url}`);
var filePath = path.join(__dirname, '../vanilla/index.html');
fs.readFile(filePath, 'utf-8', (err, html) => {
if (err) {
console.error(err);
res.send(err);
return;
}
renderer.hydrateToString(
{
html: html,
req: req,
config: {}
},
function(err, html) {
res.send(html);
}
);
});
});
app.get('/dist/*', function (req, res) {
// manually serve other dist files
var filePath = path.join(__dirname, '../../', req.url);
console.log(filePath)
fs.readFile(filePath, 'utf-8', (err, data) => {
res.send(data);
});
});
app.listen(3000, () => {
console.log('app listening on port 3000!');
});