Skip to content

Commit 662a3d3

Browse files
committed
Removed data.7z
1 parent e74e25c commit 662a3d3

File tree

4 files changed

+179
-0
lines changed

4 files changed

+179
-0
lines changed

data.7z

-341 KB
Binary file not shown.

pm2Start.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
require('dotenv').load();
2+
var pm2 = require('pm2');
3+
var nodemailer = require('nodemailer');
4+
var moment = require('moment-timezone');
5+
var _ = require('lodash');
6+
7+
var instances = process.env.INSTANCES || 1;
8+
var serverName = process.env.SERVER_NAME || 'server';
9+
var maxMemory = process.env.MAX_MEMORY || '390M';
10+
var transportOptions = {
11+
type: 'smtp',
12+
service: 'Mandrill',
13+
auth: {
14+
user: process.env.MANDRILL_USER || false,
15+
pass: process.env.MANDRILL_PASSWORD
16+
}
17+
};
18+
19+
var mailReceiver = process.env.MAIL_RECEIVER || false;
20+
21+
pm2.connect(function() {
22+
pm2.start({
23+
name: serverName,
24+
script: 'server/production-start.js',
25+
'exec_mode': 'cluster',
26+
instances: instances,
27+
'max_memory_restart': maxMemory,
28+
'NODE_ENV': 'production'
29+
}, function() {
30+
console.log(
31+
'pm2 started %s with %s instances at %s max memory',
32+
serverName,
33+
instances,
34+
maxMemory
35+
);
36+
pm2.disconnect();
37+
});
38+
});
39+
40+
41+
if (transportOptions.auth.user && mailReceiver) {
42+
console.log('setting up mailer');
43+
var transporter = nodemailer.createTransport(transportOptions);
44+
var compiled = _.template(
45+
'An error has occurred on server ' +
46+
'<% name %>\n' +
47+
'Stack Trace:\n\n\n<%= stack %>\n\n\n' +
48+
'Context:\n\n<%= text %>'
49+
);
50+
51+
pm2.launchBus(function(err, bus) {
52+
if (err) {
53+
return console.error(err);
54+
}
55+
console.log('event bus connected');
56+
57+
bus.on('process:exception', function(data) {
58+
var text;
59+
var stack;
60+
var name;
61+
try {
62+
data.date = moment(data.at || new Date())
63+
.tz('America/Los_Angeles')
64+
.format('MMMM Do YYYY, h:mm:ss a z');
65+
66+
text = JSON.stringify(data, null, 2);
67+
stack = data.data.stack;
68+
name = data.process.name;
69+
} catch (e) {
70+
return e;
71+
}
72+
73+
transporter.sendMail({
74+
to: mailReceiver,
75+
76+
subject: 'Server exception',
77+
text: compiled({ name: name, text: text, stack: stack })
78+
});
79+
});
80+
});
81+
}

webpack.config.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
var webpack = require('webpack');
2+
var path = require('path');
3+
var webpack = require('webpack');
4+
5+
var __DEV__ = process.env.NODE_ENV !== 'production';
6+
7+
module.exports = {
8+
entry: './client',
9+
output: {
10+
filename: 'bundle.js',
11+
path: path.join(__dirname, '/public/js'),
12+
publicPath: 'public/'
13+
},
14+
module: {
15+
loaders: [
16+
{
17+
test: /\.jsx?$/,
18+
include: [
19+
path.join(__dirname, 'client/'),
20+
path.join(__dirname, 'common/')
21+
],
22+
loaders: [
23+
'babel-loader'
24+
]
25+
},
26+
{
27+
test: /\.json$/,
28+
loaders: [
29+
'json-loader'
30+
]
31+
}
32+
]
33+
},
34+
plugins: [
35+
new webpack.optimize.DedupePlugin(),
36+
new webpack.optimize.OccurenceOrderPlugin(true),
37+
new webpack.DefinePlugin({
38+
'process.env': {
39+
'NODE_ENV': JSON.stringify(__DEV__ ? 'development' : 'production')
40+
},
41+
'__DEVTOOLS__': !__DEV__
42+
})
43+
]
44+
};

webpack.config.node.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
var fs = require('fs');
2+
var path = require('path');
3+
var webpack = require('webpack');
4+
5+
var nodeModules = fs.readdirSync('node_modules')
6+
.filter(function(x) {
7+
return ['.bin'].indexOf(x) === -1;
8+
})
9+
.reduce(function(nodeModules, module) {
10+
nodeModules[module] = 'commonjs ' + module;
11+
return nodeModules;
12+
}, {});
13+
14+
module.exports = {
15+
devtool: 'sourcemap',
16+
target: 'node',
17+
entry: './common/app',
18+
// keeps webpack from bundling modules
19+
externals: nodeModules,
20+
output: {
21+
filename: 'app-stream.bundle.js',
22+
path: path.join(__dirname, '/server'),
23+
publicPath: 'public/'
24+
},
25+
module: {
26+
loaders: [
27+
{
28+
test: /\.jsx?$/,
29+
include: [
30+
path.join(__dirname, 'client/'),
31+
path.join(__dirname, 'common/')
32+
],
33+
loaders: [
34+
'babel-loader'
35+
]
36+
},
37+
{
38+
test: /\.json$/,
39+
loaders: [
40+
'json-loader'
41+
]
42+
}
43+
]
44+
},
45+
plugins: [
46+
new webpack.BannerPlugin(
47+
'require("source-map-support").install();',
48+
{
49+
raw: true,
50+
entryOnly: false
51+
}
52+
)
53+
]
54+
};

0 commit comments

Comments
 (0)