-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebServer.py
75 lines (57 loc) · 1.66 KB
/
webServer.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from flask import Flask, render_template
from flask import jsonify
from flask import request, Response
from flask import abort
from flask_cors import CORS
import json
# import SearchSystem
from SearchSystem import searchService
# import webbrowser
# from SearchSystem import tools
# from SearchSystem import searchService
# from gevent.wsgi import WSGIServer
# from gevent import monkey
app = Flask(__name__,
static_url_path="",
static_folder="./dist",
template_folder="./dist")
# 热更新
app.jinja_env.auto_reload = True
# app.config['TEMPLATES_AUTO_RELOAD'] = True
# 解决跨域
cors = CORS(app, resources={r"/api/*": {"origins": "*"}})
port = "8080"
@app.route('/')
def index():
return app.send_static_file("index.html")
@app.route('/api/authUser', methods=["POST"])
def authUser():
pkt = request.get_json()
print(pkt)
return jsonify({
"msg": "ok",
"id": 123
})
#
# params={"fetchWays":int}
# searWord:str
@app.route('/api/getArticles', methods=["GET"])
def getPages():
print(request.args)
searchWord = request.args['searchWord']
searchChoice = int(request.args["searchChoice"])
resultList = searchService.runservice(searchChoice, searchWord)
return jsonify({
"resultList": resultList
})
@app.route('/api/getArticleContent', methods=["GET"])
def getPageArticle():
pageID = request.args["pageID"]
title, content = searchService.getArticle(pageID)
return jsonify({
"title":title,
"content":content
})
if __name__ == '__main__':
# webbrowser.open("http://127.0.0.1:"+port)
app.run(processes=True,host="0.0.0.0", port=port)