-
Notifications
You must be signed in to change notification settings - Fork 3
/
api.py
executable file
·29 lines (23 loc) · 910 Bytes
/
api.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
from flask import Flask, jsonify,request
from flask_restful import Resource, Api
from flask_cors import CORS, cross_origin
from query import query
app = Flask(__name__)
api = Api(app)
@app.after_request
def after_request(response):
response.headers.add('Access-Control-Allow-Origin', 'http://localhost:3000')
response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization')
response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS')
response.headers.add('Access-Control-Allow-Credentials', 'true')
return response
searchtext = ''
class HelloWorld(Resource):
def get(self):
return {"answer" : query(searchtext,20)}
def post(self):
searchtext = request.json['data']
return {'answer': query(searchtext,20)}
api.add_resource(HelloWorld, '/',methods=['GET', 'POST','PUT'])
if __name__ == '__main__':
app.run(debug=True)