Skip to content

Commit

Permalink
gh-133: Start to fix app ts
Browse files Browse the repository at this point in the history
  • Loading branch information
littlewhywhat committed Mar 31, 2020
1 parent 9491012 commit b9e04f8
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions backend/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as express from 'express'
import { Response, Request } from 'express'
import { NextFunction, Response, Request } from 'express'
import * as bodyParser from 'body-parser'

import * as storage from './storage/Storage'
Expand All @@ -11,14 +11,15 @@ import { makeBot, SingleChannelBot } from './bot/bot-factory'

import { MatchReporter } from './match-reporter/MatchReporter'
import { MatchDescription } from './types/MatchDescription'
import { InputError } from './errors/InputError'

const jsonParser = bodyParser.json()
const urlencodedParser = bodyParser.urlencoded({ extended: false })

const app = express()
const port = 3000

const addCrossDomainHeaders = function(req, res, next): void {
const addCrossDomainHeaders = function(req: Request, res: Response, next: NextFunction): void {
res.header('Access-Control-Allow-Origin', '*')
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE')
res.header('Access-Control-Allow-Headers', 'Content-Type')
Expand All @@ -29,15 +30,15 @@ app.use(addCrossDomainHeaders)
app.use(urlencodedParser)
app.use(jsonParser)

let matchReporter
let matchReporter: MatchReporter
makeBot(process.env.FOOSBOT_TOKEN, process.env.FOOS_CHANNEL_NAME)
.then((bot: SingleChannelBot) => {
matchReporter = new MatchReporter(bot, process.env.MATCH_REPORT_PREFIX_SUFFIX_CONFIG)
console.log('Slackbot initialized!')
})
.catch(error => console.warn('Slackbot initialization failed:', error.message))

const processError = (response, error): void => {
const processError = (response: Response, error: InputError): void => {
console.error(error)
response.statusCode = error.httpStatusCode || 500
response.send(error.message)
Expand Down

0 comments on commit b9e04f8

Please sign in to comment.