{"action":"created","comment":{"url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/pulls/comments/229712957","pull_request_review_id":170276207,"id":229712957,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIyOTcxMjk1Nw==","diff_hunk":"@@ -1,86 +1,94 @@\n-import { createConnection } from \"typeorm\";\n+import \"reflect-metadata\"; // this shim is required\n+import { useExpressServer } from \"routing-controllers\";\n+import connection from \"./connection\";\n+import express = require(\"express\");\n+import helmet = require(\"helmet\");\n \n (async () => {\n-  const express = require(\"express\");\n   const bodyParser = require(\"body-parser\");\n   const nunjucks = require(\"nunjucks\");\n   const logger = require(\"./infrastructure/logger\");\n   const https = require(\"https\");\n   const path = require(\"path\");\n   const config = require(\"./infrastructure/config\");\n-  const helmet = require(\"helmet\");\n-  const sanitization = require(\"login.dfe.sanitization\");\n   const healthCheck = require(\"login.dfe.healthcheck\");\n   const { getErrorHandler } = require(\"login.dfe.express-error-handling\");\n-  const routes = require(\"./routes\");\n \n-  try {\n-    const dbConnection = await createConnection();\n+  var dbMigrationPromise = connection.then(c =>\n     // Run migrations on start up; only boot up if migrations succeed!\n-    dbConnection.runMigrations({ transaction: true });\n-  } catch (err) {\n-    throw new Error(`Could not boot application, failed to connect to database, error: ${err}`);\n-  }\n-\n-  const app = express();\n-  app.use(\n-    helmet({\n-      noCache: true,\n-      frameguard: {\n-        action: \"deny\"\n-      }\n-    })\n+    c.runMigrations({ transaction: true })\n   );\n \n-  const appViews = path.join(__dirname, \"views\");\n-\n-  nunjucks.configure(appViews, {\n-    autoescape: true,\n-    express: app,\n-    noCache: true,\n-    watch: true\n+  dbMigrationPromise.catch(err => {\n+    throw new Error(\"Could not migrate database\");\n   });\n \n-  app.use(bodyParser.urlencoded({ extended: true }));\n-  app.use(sanitization());\n-  app.set(\"view engine\", \"html\");\n+  dbMigrationPromise.then(() => {\n+    var app = express();\n+    const appViews = path.join(__dirname, \"views\");\n \n-  app.use(\n-    \"/healthcheck\",\n-    healthCheck({\n-      config\n-    })\n-  );\n+    nunjucks.configure(appViews, {\n+      autoescape: true,\n+      express: app,\n+      noCache: true,\n+      watch: true\n+    });\n \n-  // Error handing\n-  app.use(\n-    getErrorHandler({\n-      logger\n-    })\n-  );\n+    app.use(bodyParser.urlencoded({ extended: true }));\n+    app.set(\"view engine\", \"html\");\n \n-  app.use(\"/\", routes);\n+    app.use(\n+      helmet({\n+        noCache: true,\n+        frameguard: {\n+          action: \"deny\"\n+        }\n+      })\n+    );\n \n-  if (config.hostingEnvironment.env === \"dev\") {\n-    app.proxy = true;\n+    app.use(\n+      \"/healthcheck\",\n+      healthCheck({\n+        config\n+      })\n+    );\n \n-    const options = {\n-      key: config.hostingEnvironment.sslKey,\n-      cert: config.hostingEnvironment.sslCert,\n-      requestCert: false,\n-      rejectUnauthorized: false\n-    };\n-    const server = https.createServer(options, app);\n+    // Error handing\n+    app.use(\n+      getErrorHandler({\n+        logger\n+      })\n+    );\n \n-    server.listen(config.hostingEnvironment.port, () => {\n-      logger.info(\n-        `Dev server listening on https://${config.hostingEnvironment.host}:${config.hostingEnvironment.port}`\n-      );\n-    });\n-  } else {\n-    app.set(\"trust proxy\", 1);\n-    app.listen(process.env.PORT, () => {\n-      logger.info(`Server listening on http://${config.hostingEnvironment.host}:${config.hostingEnvironment.port}`);\n+    useExpressServer(app, {\n+      controllers: [__dirname + \"/controllers/*.js\"]","path":"src/index.ts","position":120,"original_position":125,"commit_id":"887e9b6c583ed79fe5004fad0fa6c8eb271026a2","original_commit_id":"82e626663c5a3ad7d60a20e4bca100a831615215","user":{"login":"dankmitchell","id":3071606,"node_id":"MDQ6VXNlcjMwNzE2MDY=","avatar_url":"https://avatars3.githubusercontent.com/u/3071606?v=4","gravatar_id":"","url":"https://api.github.com/users/dankmitchell","html_url":"https://github.com/dankmitchell","followers_url":"https://api.github.com/users/dankmitchell/followers","following_url":"https://api.github.com/users/dankmitchell/following{/other_user}","gists_url":"https://api.github.com/users/dankmitchell/gists{/gist_id}","starred_url":"https://api.github.com/users/dankmitchell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dankmitchell/subscriptions","organizations_url":"https://api.github.com/users/dankmitchell/orgs","repos_url":"https://api.github.com/users/dankmitchell/repos","events_url":"https://api.github.com/users/dankmitchell/events{/privacy}","received_events_url":"https://api.github.com/users/dankmitchell/received_events","type":"User","site_admin":false},"body":"Ship it","created_at":"2018-10-31T14:19:55Z","updated_at":"2018-10-31T14:19:56Z","html_url":"https://github.com/DFE-Digital/bat-node-prototype/pull/10#discussion_r229712957","pull_request_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/pulls/10","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/pulls/comments/229712957"},"html":{"href":"https://github.com/DFE-Digital/bat-node-prototype/pull/10#discussion_r229712957"},"pull_request":{"href":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/pulls/10"}},"in_reply_to_id":229703887},"pull_request":{"url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/pulls/10","id":227244202,"node_id":"MDExOlB1bGxSZXF1ZXN0MjI3MjQ0MjAy","html_url":"https://github.com/DFE-Digital/bat-node-prototype/pull/10","diff_url":"https://github.com/DFE-Digital/bat-node-prototype/pull/10.diff","patch_url":"https://github.com/DFE-Digital/bat-node-prototype/pull/10.patch","issue_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/issues/10","number":10,"state":"open","locked":false,"title":"proposing a controller based routing pattern","user":{"login":"the-daniel-rothig","id":5263266,"node_id":"MDQ6VXNlcjUyNjMyNjY=","avatar_url":"https://avatars1.githubusercontent.com/u/5263266?v=4","gravatar_id":"","url":"https://api.github.com/users/the-daniel-rothig","html_url":"https://github.com/the-daniel-rothig","followers_url":"https://api.github.com/users/the-daniel-rothig/followers","following_url":"https://api.github.com/users/the-daniel-rothig/following{/other_user}","gists_url":"https://api.github.com/users/the-daniel-rothig/gists{/gist_id}","starred_url":"https://api.github.com/users/the-daniel-rothig/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/the-daniel-rothig/subscriptions","organizations_url":"https://api.github.com/users/the-daniel-rothig/orgs","repos_url":"https://api.github.com/users/the-daniel-rothig/repos","events_url":"https://api.github.com/users/the-daniel-rothig/events{/privacy}","received_events_url":"https://api.github.com/users/the-daniel-rothig/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-10-31T11:09:08Z","updated_at":"2018-10-31T14:19:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9f1586bbda110e1e17db23f6390389cda558d274","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/pulls/10/commits","review_comments_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/pulls/10/comments","review_comment_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/pulls/comments{/number}","comments_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/issues/10/comments","statuses_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/statuses/887e9b6c583ed79fe5004fad0fa6c8eb271026a2","head":{"label":"DFE-Digital:controller-router","ref":"controller-router","sha":"887e9b6c583ed79fe5004fad0fa6c8eb271026a2","user":{"login":"DFE-Digital","id":30029772,"node_id":"MDEyOk9yZ2FuaXphdGlvbjMwMDI5Nzcy","avatar_url":"https://avatars3.githubusercontent.com/u/30029772?v=4","gravatar_id":"","url":"https://api.github.com/users/DFE-Digital","html_url":"https://github.com/DFE-Digital","followers_url":"https://api.github.com/users/DFE-Digital/followers","following_url":"https://api.github.com/users/DFE-Digital/following{/other_user}","gists_url":"https://api.github.com/users/DFE-Digital/gists{/gist_id}","starred_url":"https://api.github.com/users/DFE-Digital/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DFE-Digital/subscriptions","organizations_url":"https://api.github.com/users/DFE-Digital/orgs","repos_url":"https://api.github.com/users/DFE-Digital/repos","events_url":"https://api.github.com/users/DFE-Digital/events{/privacy}","received_events_url":"https://api.github.com/users/DFE-Digital/received_events","type":"Organization","site_admin":false},"repo":{"id":155372200,"node_id":"MDEwOlJlcG9zaXRvcnkxNTUzNzIyMDA=","name":"bat-node-prototype","full_name":"DFE-Digital/bat-node-prototype","private":false,"owner":{"login":"DFE-Digital","id":30029772,"node_id":"MDEyOk9yZ2FuaXphdGlvbjMwMDI5Nzcy","avatar_url":"https://avatars3.githubusercontent.com/u/30029772?v=4","gravatar_id":"","url":"https://api.github.com/users/DFE-Digital","html_url":"https://github.com/DFE-Digital","followers_url":"https://api.github.com/users/DFE-Digital/followers","following_url":"https://api.github.com/users/DFE-Digital/following{/other_user}","gists_url":"https://api.github.com/users/DFE-Digital/gists{/gist_id}","starred_url":"https://api.github.com/users/DFE-Digital/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DFE-Digital/subscriptions","organizations_url":"https://api.github.com/users/DFE-Digital/orgs","repos_url":"https://api.github.com/users/DFE-Digital/repos","events_url":"https://api.github.com/users/DFE-Digital/events{/privacy}","received_events_url":"https://api.github.com/users/DFE-Digital/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/DFE-Digital/bat-node-prototype","description":null,"fork":false,"url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype","forks_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/forks","keys_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/keys{/key_id}","collaborators_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/teams","hooks_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/hooks","issue_events_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/issues/events{/number}","events_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/events","assignees_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/assignees{/user}","branches_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/branches{/branch}","tags_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/tags","blobs_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/git/refs{/sha}","trees_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/git/trees{/sha}","statuses_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/statuses/{sha}","languages_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/languages","stargazers_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/stargazers","contributors_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/contributors","subscribers_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/subscribers","subscription_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/subscription","commits_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/commits{/sha}","git_commits_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/git/commits{/sha}","comments_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/comments{/number}","issue_comment_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/issues/comments{/number}","contents_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/contents/{+path}","compare_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/compare/{base}...{head}","merges_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/merges","archive_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/downloads","issues_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/issues{/number}","pulls_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/pulls{/number}","milestones_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/milestones{/number}","notifications_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/labels{/name}","releases_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/releases{/id}","deployments_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/deployments","created_at":"2018-10-30T11:15:20Z","updated_at":"2018-10-31T14:19:23Z","pushed_at":"2018-10-31T14:19:25Z","git_url":"git://github.com/DFE-Digital/bat-node-prototype.git","ssh_url":"git@github.com:DFE-Digital/bat-node-prototype.git","clone_url":"https://github.com/DFE-Digital/bat-node-prototype.git","svn_url":"https://github.com/DFE-Digital/bat-node-prototype","homepage":null,"size":136,"stargazers_count":0,"watchers_count":0,"language":"TypeScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"DFE-Digital:master","ref":"master","sha":"804fac36c7ca99f1d80f9507b6bfcfeb31e5d793","user":{"login":"DFE-Digital","id":30029772,"node_id":"MDEyOk9yZ2FuaXphdGlvbjMwMDI5Nzcy","avatar_url":"https://avatars3.githubusercontent.com/u/30029772?v=4","gravatar_id":"","url":"https://api.github.com/users/DFE-Digital","html_url":"https://github.com/DFE-Digital","followers_url":"https://api.github.com/users/DFE-Digital/followers","following_url":"https://api.github.com/users/DFE-Digital/following{/other_user}","gists_url":"https://api.github.com/users/DFE-Digital/gists{/gist_id}","starred_url":"https://api.github.com/users/DFE-Digital/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DFE-Digital/subscriptions","organizations_url":"https://api.github.com/users/DFE-Digital/orgs","repos_url":"https://api.github.com/users/DFE-Digital/repos","events_url":"https://api.github.com/users/DFE-Digital/events{/privacy}","received_events_url":"https://api.github.com/users/DFE-Digital/received_events","type":"Organization","site_admin":false},"repo":{"id":155372200,"node_id":"MDEwOlJlcG9zaXRvcnkxNTUzNzIyMDA=","name":"bat-node-prototype","full_name":"DFE-Digital/bat-node-prototype","private":false,"owner":{"login":"DFE-Digital","id":30029772,"node_id":"MDEyOk9yZ2FuaXphdGlvbjMwMDI5Nzcy","avatar_url":"https://avatars3.githubusercontent.com/u/30029772?v=4","gravatar_id":"","url":"https://api.github.com/users/DFE-Digital","html_url":"https://github.com/DFE-Digital","followers_url":"https://api.github.com/users/DFE-Digital/followers","following_url":"https://api.github.com/users/DFE-Digital/following{/other_user}","gists_url":"https://api.github.com/users/DFE-Digital/gists{/gist_id}","starred_url":"https://api.github.com/users/DFE-Digital/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DFE-Digital/subscriptions","organizations_url":"https://api.github.com/users/DFE-Digital/orgs","repos_url":"https://api.github.com/users/DFE-Digital/repos","events_url":"https://api.github.com/users/DFE-Digital/events{/privacy}","received_events_url":"https://api.github.com/users/DFE-Digital/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/DFE-Digital/bat-node-prototype","description":null,"fork":false,"url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype","forks_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/forks","keys_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/keys{/key_id}","collaborators_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/teams","hooks_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/hooks","issue_events_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/issues/events{/number}","events_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/events","assignees_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/assignees{/user}","branches_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/branches{/branch}","tags_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/tags","blobs_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/git/refs{/sha}","trees_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/git/trees{/sha}","statuses_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/statuses/{sha}","languages_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/languages","stargazers_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/stargazers","contributors_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/contributors","subscribers_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/subscribers","subscription_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/subscription","commits_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/commits{/sha}","git_commits_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/git/commits{/sha}","comments_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/comments{/number}","issue_comment_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/issues/comments{/number}","contents_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/contents/{+path}","compare_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/compare/{base}...{head}","merges_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/merges","archive_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/downloads","issues_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/issues{/number}","pulls_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/pulls{/number}","milestones_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/milestones{/number}","notifications_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/labels{/name}","releases_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/releases{/id}","deployments_url":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/deployments","created_at":"2018-10-30T11:15:20Z","updated_at":"2018-10-31T14:19:23Z","pushed_at":"2018-10-31T14:19:25Z","git_url":"git://github.com/DFE-Digital/bat-node-prototype.git","ssh_url":"git@github.com:DFE-Digital/bat-node-prototype.git","clone_url":"https://github.com/DFE-Digital/bat-node-prototype.git","svn_url":"https://github.com/DFE-Digital/bat-node-prototype","homepage":null,"size":136,"stargazers_count":0,"watchers_count":0,"language":"TypeScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/pulls/10"},"html":{"href":"https://github.com/DFE-Digital/bat-node-prototype/pull/10"},"issue":{"href":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/issues/10"},"comments":{"href":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/issues/10/comments"},"review_comments":{"href":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/pulls/10/comments"},"review_comment":{"href":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/pulls/10/commits"},"statuses":{"href":"https://api.github.com/repos/DFE-Digital/bat-node-prototype/statuses/887e9b6c583ed79fe5004fad0fa6c8eb271026a2"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"dankmitchell"}}