-
Notifications
You must be signed in to change notification settings - Fork 27
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
1 parent
9dbcf15
commit 2855ccc
Showing
4 changed files
with
83 additions
and
38 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,73 @@ | ||
import {Observable, Subject} from '@reactivex/rxjs'; | ||
import {Server} from 'ws'; | ||
import {createServer} from 'http'; | ||
import * as express from 'express'; | ||
import * as fs from 'fs'; | ||
import 'es6-shim'; | ||
|
||
var app = express(); | ||
|
||
let stocks = require('../data/nyse-listed.json').map(stock => { | ||
return { | ||
company_name: stock['Company Name'], | ||
symbol: stock['ACT Symbol'] | ||
} | ||
}); | ||
|
||
const searchStocks = query => { | ||
query.symbol = query.symbol ? query.symbol.toLowerCase() : false; | ||
query.company_name = query.company_name ? query.company_name.toLowerCase() : false; | ||
|
||
return (stock) => { | ||
//prefer symbol | ||
if(query.symbol){ | ||
return stock.symbol.toLowerCase().startsWith(query.symbol); | ||
} | ||
return stock.company_name.toLowerCase().startsWith(query.company_name); | ||
} | ||
} | ||
|
||
|
||
app.get('/stocks', function (req, res) { | ||
if(!req.query.company_name && !req.query.symbol){ | ||
return res.json([]); | ||
} | ||
res.json(stocks.filter(searchStocks(req.query))); | ||
}); | ||
|
||
var server = app.listen(3000, function () { | ||
var host = server.address().address; | ||
var port = server.address().port; | ||
|
||
console.log('Stock Server app listening at http://%s:%s', host, port); | ||
}); | ||
|
||
// //creates a new server socket Subject | ||
// const createRxSocket = (connection) => { | ||
// let messages = Observable.fromEvent(connection, 'message', null); | ||
// let messageObserver:any = { | ||
// next(message){ | ||
// connection.send(message); | ||
// } | ||
// } | ||
// return Subject.create(messages, messageObserver); | ||
// } | ||
|
||
// //creates an instance of the websocket server; | ||
// const createRxServer = (options) => { | ||
// return new Observable(serverObserver => { | ||
// console.info('started server...'); | ||
// let wss = new Server(options); | ||
// wss.on('connection', connection => serverObserver.next(connection)); | ||
// return () => { | ||
// wss.close(); | ||
// } | ||
// }); | ||
// } | ||
|
||
// const server = createRxServer({port: 8081}); | ||
// const connections = server.map(createRxSocket); | ||
|
||
// let messageEvents$ = connections.flatMap(connection => connection.map(message => ({connection, message}))); | ||
|
||
// messageEvents$.subscribe(message => console.log('message', message)) |