 	proxy: settings.behindProxy
 ))
 
+destroySession = (req, res, next) ->
+	res.session?.destory()
+	next()
+
 app.use(AuthenticationController.setupLoginStatus)
 
 app.get("#{mountPoint}/", IndexController.index)

	
app.post("#{mountPoint}/repos/:owner/:repo/builds/latest", bodyParser(), csrf, AuthenticationController.requireLogin, BuildController.buildLatestCommit)

app.get "#{mountPoint}/status", (req, res, next) ->
	res.send("github-latex-ci is alive")
	req.session.destroy()

port = settings.internal.github_latex_ci.port
host = settings.internal.github_latex_ci.host


app.post("#{mountPoint}/repos/:owner/:repo/hook", bodyParser(), csrf, AuthenticationController.requireLogin, WebHookController.createHook)
app.post("#{mountPoint}/repos/:owner/:repo/hook/destroy", bodyParser(), csrf, AuthenticationController.requireLogin, WebHookController.destroyHook)
app.post("#{mountPoint}/events", destroySession, WebHookController.webHookEvent)

app.get("#{mountPoint}/repos/:owner/:repo/builds/:sha", BuildController.showBuild)
app.get("#{mountPoint}/repos/:owner/:repo/builds/latest/badge.svg", BuildController.latestPdfBadge)
