-
Notifications
You must be signed in to change notification settings - Fork 6
/
server.js
executable file
·104 lines (98 loc) · 2.31 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**
* @jsx React.DOM
*/
'use strict';
//require('node-jsx').install({extension: '.jsx'});
var path = require('path'),
url = require('url'),
connect = require('connect'),
React = require('react'),
ReactAsync = require('react-async'),
serveStatic = require('serve-static'),
webpack = require('webpack'),
webpackDevMiddleware = require("webpack-dev-middleware"),
Root = React.createFactory(require('./public/components/Root')),
Router = require('react-router'),
web = connect(),
url = require('url'),
exec = require('child_process').exec;
var port = process.env.PORT || 5000;
/*var compiler = webpack({
entry: __dirname + '/index.js',
output: {
path: __dirname,
publicPath: "/bundle/",
filename: 'bundle.js'
},
resolve: {
modulesDirectories: [
'public',
'components',
'scripts',
'stylesheets',
'node_modules',
'terms',
'js'
],
// Allow to omit extensions when requiring these files
extensions: ['', '.js', '.jsx', 'json']
},
module: {
plugins: [
new webpack.dependencies.LabeledModulesPlugin()
],
loaders: [
{ test: /\.css$/, loader: "style!css" },
{ test: /\.json$/, loader: "json-loader" },
{ test: /\.jsx$/, loader: "jsx-loader?harmony" },
{
test: /\.png$/,
loader: "url-loader",
query: { mimetype: "image/png" }
},
{
test: /\.svg$/,
loader: "url-loader",
query: { mimetype: "image/svg" }
},
{ test: /\.ttf|eot|woff$/, loader: "url-loader" },
]
}
});
web.use(webpackDevMiddleware(compiler, {
publicPath: "/bundle/"
}));*/
web.use(
function(req, res, next) {
if (
req.url.indexOf('favicon') > 0 ||
req.url.indexOf('images') > 0 ||
req.url.indexOf('css') > 0 ||
req.url.indexOf('script') > 0
) {
next();
} else {
try {
Router.run(
require('./public/components/routes'),
req.url,
function (Handler, state) {
res.end(React.renderToString(Handler()));
}
);
} catch(err) {
return next(err)
}
}
}
);
web.use(serveStatic('public'));
exec('node build', function(err) {
if (err) {
console.log(err);
} else {
web.listen(port, function() {
console.log('Listening on ' + port);
});
}
});