Skip to content

Commit

Permalink
Extracted connection setup into own method, made sure that httpOnly i…
Browse files Browse the repository at this point in the history
…s given as boolean
  • Loading branch information
martinheidegger committed Mar 29, 2016
1 parent 1e0be5c commit 81d7ae7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 24 deletions.
2 changes: 1 addition & 1 deletion bin/open-github-teams
Expand Up @@ -2,7 +2,7 @@

require('../lib/hapiServer')({
connection: {
httpOnly: process.env.HTTP_ONLY,
httpOnly: /^\s*true|yes\s*$/ig.test(process.env.HTTP_ONLY),
email: process.env.HTTPS_EMAIL,
agreeTos: process.env.HTTPS_AGREE === 'yes',
http: process.env.HTTP_PORT || 80,
Expand Down
2 changes: 2 additions & 0 deletions lib/githubApiForToken.js
@@ -1,3 +1,5 @@
'use strict'

module.exports = function (token) {
var GitHubApi = require('github')
var github = new GitHubApi({
Expand Down
24 changes: 24 additions & 0 deletions lib/hapiConnection.js
@@ -0,0 +1,24 @@
'use strict'

module.exports = function (options) {
if (options.httpOnly) {
return {
port: options.http || 80
}
}
var createServer = require('auto-sni')
return {
listener: createServer({
// we need SSL for the webhook but the access is just-fine™ via http
forceSSL: false,
email: options.email,
agreeTos: options.agreeTos,
ports: {
http: options.http,
https: options.https
}
}),
autoListen: false,
tls: true
}
}
1 change: 1 addition & 0 deletions lib/hapiPlugin.js
@@ -1,4 +1,5 @@
'use strict'

var Path = require('path')

function registerHapiPlugin (server, options, next) {
Expand Down
27 changes: 4 additions & 23 deletions lib/hapiServer.js
@@ -1,33 +1,14 @@
'use strict'

var hapi = require('hapi')

module.exports = function (options, callback) {
var conn

if (options.openGithubTeams.secret && (options.connection.httpOnly || '').toLowerCase() !== 'true') {
var createServer = require('auto-sni')
conn = {
listener: createServer({
// we need SSL for the webhook but the access is just-fine™ via http
forceSSL: false,
email: options.connection.email,
agreeTos: options.connection.agreeTos,
ports: {
http: options.connection.http,
https: options.connection.https
}
}),
autoListen: false,
tls: true
}
} else {
conn = {
port: options.connection.http || 80
}
if (!options.openGithubTeams.secret) {
options.connection.httpOnly = true
}

var server = new hapi.Server()
server.connection(conn)
server.connection(require('./hapiConnection.js')(options.connection))
server.register([{
register: require('good'),
options: {
Expand Down

0 comments on commit 81d7ae7

Please sign in to comment.