This repository was archived by the owner on Oct 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
60 lines (48 loc) · 1.58 KB
/
server.js
File metadata and controls
60 lines (48 loc) · 1.58 KB
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
56
57
58
59
60
//testing lib
import util from 'util';
import 'babel/register';
import { RoutingContext, match, createRoutes} from 'react-router'
import React from 'react';
import createLocation from 'history/lib/createLocation';
import {server, renderToString} from "react-dom/server";
import express from 'express';
import exphbs from 'express-handlebars';
import registrar from 'handlebars-registrar';
import handlebars from 'handlebars';
import path from 'path';
import config from './config';
import paths_app from './paths-app';
import paths_vendor from './paths-vendor';
var paths = {
app: paths_app,
vendor: paths_vendor
};
var app = express();
registrar(handlebars, {
helpers: paths.app.helpers.src,
partials: paths.app.templates.src
});
var hbs = exphbs.create({
extname: '.hbs',
helpers: handlebars.helpers,
partialsDir: __dirname + "/src/"
});
app.engine('hbs', hbs.engine);
app.set('view engine', 'hbs');
app.set('views', path.join(__dirname, "/src/app/"));
app.use(express.static(path.join(__dirname, 'public')));
/// react-router magic
app.use(function(req, res, next) {
const jsx = require(config.srcDir + "/app/app_jsx.jsx");
var routes = createRoutes(jsx.routes_manager());
var location = createLocation(req.url, req.query);
match({routes, location}, function(error, redirectLocation, renderProps) {
var App = React.createFactory(RoutingContext)(renderProps);
res.render('app-layout', {
reactHtml: React.renderToStaticMarkup(App)
});
});
});
var webServer = app.listen(config.port, function(){
console.log('App listening at port ' + config.port);
});