Skip to content

Commit c28119e

Browse files
author
Andreas Savvides
committed
Merge branch 'brandonblack-ruby-backend'
Conflicts: server.py
2 parents 8304589 + 7cecaff commit c28119e

File tree

7 files changed

+60
-6
lines changed

7 files changed

+60
-6
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Desktop.ini
2626
$RECYCLE.BIN/
2727

2828
# App specific
29-
29+
Gemfile.lock
3030
node_modules/
3131
.tmp
3232
dist

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source 'https://rubygems.org'
2+
3+
gem 'sinatra'
4+
gem 'multi_json'

Gruntfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module.exports = function (grunt) {
1212
options: {
1313
entry: "./src/ReactDigits.js",
1414
output: {
15-
path: "./dist/",
15+
path: "./public/dist/",
1616
filename: "dist.js",
1717
},
1818
stats: {

README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,27 @@ Now open [`src/ReactDigits.js`](src/ReactDigits.js) and enter your consumer key
2020

2121
You can find your consumer key in your [Fabric web dashboard](https://fabric.io/dashboard) under the Twitter Kit tab. Note that Digits does not work with keys created from [apps.twitter.com](apps.twitter.com).
2222

23-
### Running a server in another terminal
23+
### Running the Server
2424

25+
##### Python
2526
```bash
27+
# install pre-requisites
28+
pip install -r requirements.pip
29+
30+
# start the server (in a separate tab)
2631
python server.py
2732
```
2833

34+
##### Ruby
35+
```bash
36+
# install pre-requisites
37+
gem install bundler
38+
bundle install
39+
40+
# start the server (in a separate tab)
41+
ruby server.rb
42+
```
43+
2944
Head over to `localhost:5000` and you should be able to see this code in action; try and log in using Digits!
3045

3146
## Contributing
@@ -41,4 +56,4 @@ Have a look at the [issue tracker](https://github.com/AnSavvides/react-digits/is
4156

4257
## License
4358

44-
[MIT](LICENSE)
59+
[MIT](LICENSE)
File renamed without changes.

server.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
import json
33

44
from flask import Flask
5+
from flask import Response
56
from flask import request
67
from flask import abort
78

8-
app = Flask("ReactDigitsServer", static_url_path="", static_folder="./")
9+
app = Flask("ReactDigitsServer", static_url_path="", static_folder="public")
910
app.add_url_rule("/", "root", lambda: app.send_static_file("index.html"))
11+
app.add_url_rule("/dist/*", "dist", lambda: app.send_static_file("dist/dist.js"))
1012

1113

1214
@app.route("/user/verify", methods=["POST"])
@@ -21,6 +23,6 @@ def verify_user():
2123
if response.status_code != 200:
2224
return abort(response.status_code)
2325

24-
return response.content
26+
return Response(response.content, mimetype='application/json')
2527

2628
app.run(debug=True)

server.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
require 'sinatra'
2+
require 'multi_json'
3+
require 'net/http'
4+
require 'uri'
5+
6+
configure do
7+
set :port, 5000
8+
end
9+
10+
get '/' do
11+
send_file 'public/index.html'
12+
end
13+
14+
get '/dist/dist.js' do
15+
send_file 'public/dist/dist.js'
16+
end
17+
18+
post '/user/verify' do
19+
data = MultiJson.load(request.body.read)
20+
21+
url = URI.parse(data['apiUrl'])
22+
req = Net::HTTP::Get.new(url.path)
23+
req['Authorization'] = data['authHeader']
24+
25+
http = Net::HTTP.new(url.host, url.port)
26+
http.use_ssl = true if url.scheme == 'https'
27+
res = http.request(req)
28+
29+
halt res.code.to_i, 'Error! Request failed.' unless res.code == '200'
30+
31+
content_type :json
32+
res.body
33+
end

0 commit comments

Comments
 (0)