-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Paul Gebheim
committed
Dec 28, 2017
1 parent
ed22bba
commit 2c9bec8
Showing
3 changed files
with
60 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import * as express from "express"; | ||
import * as WebSocket from "ws"; | ||
import * as Knex from "knex"; | ||
import Augur from "augur.js"; | ||
import { runWebsocketServer } from "./run-websocket-server"; | ||
import { getMarkets } from "./getters/get-markets"; | ||
import { Address, MarketsRow } from "../types"; | ||
|
||
// tslint:disable-next-line:no-var-requires | ||
const { websocketConfigs } = require("../../config"); | ||
|
||
export interface RunServerResult { | ||
app: express.Application; | ||
servers: Array<WebSocket.Server> | ||
} | ||
|
||
export function runServer(db: Knex, augur: Augur): RunServerResult { | ||
const app: express.Application = express(); | ||
|
||
const servers: Array<WebSocket.Server> = runWebsocketServer(db, app, websocketConfigs); | ||
|
||
app.get("/", (req, res) => { | ||
res.send("Hello World"); | ||
}); | ||
|
||
app.get("/status", (req, res) => { | ||
try { | ||
const networkId: string = augur.rpc.getNetworkID(); | ||
const universe: Address = augur.contracts.addresses[networkId].Universe; | ||
|
||
getMarkets(db, universe, undefined, undefined, undefined, undefined, (err: Error|null, result?: any): void => { | ||
if (result.length === 0) throw new Error("No markets exist"); | ||
|
||
res.send( { status: "up", universe } ); | ||
}); | ||
} catch(e) { | ||
res.send({status: "down", reason: e}); | ||
} | ||
}); | ||
|
||
return { app, servers }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters