Skip to content

Commit

Permalink
fix(server): pivot to stocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
robwormald committed Oct 15, 2015
1 parent 9dbcf15 commit 2855ccc
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 38 deletions.
1 change: 1 addition & 0 deletions data/nyse-listed.json

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"main": "index.js",
"scripts": {
"serve": "./node_modules/.bin/webpack-dev-server",
"build_server": "tsc server/chat_server.ts -m commonjs --outDir dist || true",
"start_server": "npm run build_server && node dist/chat_server",
"postinstall": "./node_modules/.bin/tsd install"
"postinstall": "./node_modules/.bin/tsd install",
"build_server": "tsc server/stock_server.ts -m commonjs --outDir dist || true",
"start_server": "npm run build_server && node dist/stock_server"
},
"repository": {
"type": "git",
Expand All @@ -34,9 +34,13 @@
"dependencies": {
"@reactivex/rxjs": "^5.0.0-alpha.2",
"angular2": "^2.0.0-alpha.42",
<<<<<<< HEAD
"firebase": "^2.3.1",
=======
"express": "^4.13.3",
>>>>>>> fix(server): pivot to stocks.
"reflect-metadata": "^0.1.2",
"zone.js": "^0.5.8",
"ws": "^0.8.0"
"ws": "^0.8.0",
"zone.js": "^0.5.8"
}
}
33 changes: 0 additions & 33 deletions server/chat_server.ts

This file was deleted.

73 changes: 73 additions & 0 deletions server/stock_server.ts
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))

0 comments on commit 2855ccc

Please sign in to comment.