Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nodejitsu shutting down. Modifications for new host. #635

Merged
merged 6 commits into from
May 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,47 @@ var sessionSecret = process.env.SESSION_SECRET || settings.secret;
var db = mongoose.connection;
var dbOptions = { server: { socketOptions: { keepAlive: 1 } } };

var fs = require('fs');
var http = require('http');
var https = require('https');
var sslOptions = null;
var server = http.createServer(app);
var secureServer = null;

app.set('port', process.env.PORT || 8080);
app.set('securePort', process.env.SECURE_PORT || null);

// Connect to the database
mongoose.connect(connectStr, dbOptions);
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function () {
app.listen(app.get('port'));
});
db.once('open', function () {});

var sessionStore = new MongoStore({ mongooseConnection: db });

// Force HTTPS
if (app.get('port') === 443) {
if (app.get('securePort')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sizzlemctwizzle
So you are doing this programmatically now from the environment now instead of what was done at 932d1c9 ? e.g. which no longer allows http://openuserjs.org ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't set the SECURE_PORT environment variable then it runs using
http on PORT.
On May 29, 2015 3:48 AM, "Marti Martz" [email protected] wrote:

In app.js
#635 (comment)
:

var sessionStore = new MongoStore({ mongooseConnection: db });

// Force HTTPS
-if (app.get('port') === 443) {
+if (app.get('securePort')) {

@sizzlemctwizzle https://github.com/sizzlemctwizzle
So you are doing this programmatically now from the environment now
instead of what was done at 932d1c9
932d1c9
? e.g. which no longer allows http://openuserjs.org ?


Reply to this email directly or view it on GitHub
https://github.com/OpenUserJs/OpenUserJS.org/pull/635/files#r31308229.

sslOptions = {
key: fs.readFileSync('./keys/private.key'),
cert: fs.readFileSync('./keys/cert.crt'),
ca: fs.readFileSync('./keys/intermediate.crt')
};
secureServer = https.createServer(sslOptions, app);

app.use(function (aReq, aRes, aNext) {
aRes.setHeader('Strict-Transport-Security',
'max-age=8640000; includeSubDomains');

if (aReq.headers['x-forwarded-proto'] !== 'https') {
if (!aReq.secure) {
return aRes.redirect(301, 'https://' + aReq.headers.host + encodeURI(aReq.url));
}

aNext();
});

server.listen(app.get('port'));
secureServer.listen(app.get('securePort'));
} else {
server.listen(app.get('port'));
}

if (isDev || isDbg) {
Expand Down
2 changes: 1 addition & 1 deletion controllers/scriptStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ exports.webhook = function (aReq, aRes) {
// Test for know GH webhook ips: https://api.github.com/meta
if (!aReq.body.payload ||
!/192\.30\.25[2-5]\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])$/
.test(aReq.headers['x-forwarded-for'] || aReq.connection.remoteAddress)) {
.test(aReq.connection.remoteAddress)) {
return;
}

Expand Down
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "OpenUserJS.org",
"description": "An open source user scripts repo built using Node.js",
"version": "0.1.8+0000000",
"version": "0.1.9",
"main": "app",
"dependencies": {
"ace-builds": "git://github.com/ajaxorg/ace-builds#9d12839",
Expand Down Expand Up @@ -60,10 +60,6 @@
"url": "https://github.com/OpenUserJs/OpenUserJS.org.git"
},
"license": "(GPL-3.0 AND GFDL-1.3)",
"subdomain": "openuserjs",
"domains": [
"openuserjs.org"
],
"scripts": {
"start": "node app.js",
"postinstall": "node dev/init.js"
Expand Down