-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
61 lines (52 loc) · 1.69 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!flask/bin/python
''' server.py
Description of the purpose of this file
'''
from flask import Flask, request
from flask_restful import Api
from flask_cors import CORS, cross_origin
import requests
import os
import sys
from dotenv import load_dotenv
import json
from datetime import datetime
from db import database
from visa_api import visa_api_call
load_dotenv() # Load environment variables
app = Flask(__name__)
api = Api()
cors = CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'
@app.after_request
def after_request(response):
header = response.headers
header['Access-Control-Allow-Methods'] = '*'
header['Access-Control-Allow-Headers'] = '*'
header['Access-Control-Allow-Origin'] = '*'
return response
from invoices import Invoice
from merchants import Merchant
from payment import Payment
api.add_resource(Invoice,'/invoices','/invoices/', '/invoices/<string:id>')
api.add_resource(Merchant,'/merchants','/merchants/')
api.add_resource(Payment, '/payment')
api.init_app(app)
# Testing Flask
@app.route('/')
def index():
return "Hello, World!"
# Testing visa API calls
@app.route('/visa-api-test')
def visa_api_test():
return visa_api_call('https://sandbox.api.visa.com/vdp/helloworld').content
if __name__ == '__main__': # pragma: no cover
# Checks if we have environment variables set for our TLS keys (this is optional)
fullchainpath = os.getenv("fullchainpath")
privatekeypath = os.getenv("privatekeypath")
if fullchainpath is not None and privatekeypath is not None:
context = (fullchainpath, privatekeypath)
else:
context = None
# Runs on port 5000, switch to whatever you like
app.run("0.0.0.0", 5000, app, ssl_context=context)