-
Notifications
You must be signed in to change notification settings - Fork 7
/
search_server.py
38 lines (28 loc) · 924 Bytes
/
search_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
from flask import Flask, request
app = Flask(__name__, static_folder='static/search/', static_url_path='')
import json
import sys
import coffeescript
from searcher import Searcher
@app.route('/')
def root():
return app.send_static_file('index.html')
@app.route('/search-api', methods=['POST'])
def search_api():
return app.searcher.search(request.get_json())
def compile_assets():
static = app.static_folder
with open("{}/javascript/index.js".format(static), 'w') as f:
infile = "{}/coffeescript/index.coffee".format(static)
js = coffeescript.compile_file(infile)
f.write(js)
def server(config):
print('Compiling assets...')
compile_assets()
app.searcher = Searcher(config)
return app
if __name__ == '__main__':
if len(sys.argv) != 2:
print("Usage: {} config.toml".format(sys.argv[0]))
sys.exit(1)
server(sys.argv[1]).run(debug=True)