fs-walle-react-ts/walle_server.py

42 lines
1.1 KiB
Python

from flask import Flask,send_from_directory,request
app = Flask(__name__,static_url_path='',static_folder='build')
from freespeech_walle.get_morph_rule import get_morph
# from freespeech_walle.wizard_helpers import get_morph_rule,get_frequency
import json
# from flask_cors import CORS, cross_origin
# CORS(app)
@app.route('/')
def walle_index():
return app.send_static_file('index.html')
@app.route('/api/test')
def walle_test():
return "test"
@app.route('/api/morph')
def walle_morph():
word = request.args.get('word','water')
pos_req = request.args.get('pos','N')
pos = pos_req if pos_req != '' else 'N';
return json.dumps(get_morph(word,pos))
@app.route('/api/save',methods=['POST'])
def walle_save():
print request.form
return 'ok'
# hmr streaming
# import requests
# from flask import Response,stream_with_context
# @app.route('/<path:url>',methods=['GET','POST'])
# def walle_hmr(url):
# webpack_server = 'http://localhost:3000/'
# req = requests.get(webpack_server+url, stream = True)
# return Response(stream_with_context(req.iter_content()))
if __name__ == '__main__':
app.run(debug=True)