made server multi threaded & config bugfix
This commit is contained in:
parent
a2beb5971b
commit
2baf794ae7
8
api.py
8
api.py
@ -15,7 +15,7 @@
|
|||||||
'''
|
'''
|
||||||
import flask
|
import flask
|
||||||
from flask import request, Response
|
from flask import request, Response
|
||||||
import configparser, sys, random
|
import configparser, sys, random, threading
|
||||||
'''
|
'''
|
||||||
Main API
|
Main API
|
||||||
'''
|
'''
|
||||||
@ -34,6 +34,10 @@ class API:
|
|||||||
else:
|
else:
|
||||||
self.host = '127.0.0.1'
|
self.host = '127.0.0.1'
|
||||||
|
|
||||||
|
@app.before_request
|
||||||
|
def beforeReq():
|
||||||
|
return
|
||||||
|
|
||||||
@app.after_request
|
@app.after_request
|
||||||
def afterReq(resp):
|
def afterReq(resp):
|
||||||
resp.headers['Access-Control-Allow-Origin'] = '*'
|
resp.headers['Access-Control-Allow-Origin'] = '*'
|
||||||
@ -58,7 +62,7 @@ class API:
|
|||||||
print('Starting client on ' + self.host + ':' + str(bindPort))
|
print('Starting client on ' + self.host + ':' + str(bindPort))
|
||||||
print('Client token:', clientToken)
|
print('Client token:', clientToken)
|
||||||
|
|
||||||
app.run(host=self.host, port=bindPort, debug=True)
|
app.run(host=self.host, port=bindPort, debug=True, threaded=True)
|
||||||
|
|
||||||
def validateHost(self):
|
def validateHost(self):
|
||||||
if self.debug:
|
if self.debug:
|
||||||
|
@ -24,6 +24,10 @@ class Onionr:
|
|||||||
self.debug = True # Whole application debugging
|
self.debug = True # Whole application debugging
|
||||||
|
|
||||||
os.chdir(sys.path[0])
|
os.chdir(sys.path[0])
|
||||||
|
|
||||||
|
if not os.path.exists('data'):
|
||||||
|
os.mkdir('data')
|
||||||
|
|
||||||
# Get configuration
|
# Get configuration
|
||||||
self.config = configparser.ConfigParser()
|
self.config = configparser.ConfigParser()
|
||||||
if os.path.exists('data/config.ini'):
|
if os.path.exists('data/config.ini'):
|
||||||
@ -31,7 +35,7 @@ class Onionr:
|
|||||||
else:
|
else:
|
||||||
# Generate default config
|
# Generate default config
|
||||||
# Hostname should only be set if different from 127.x.x.x. Important for DNS rebinding attack prevention.
|
# Hostname should only be set if different from 127.x.x.x. Important for DNS rebinding attack prevention.
|
||||||
if debug:
|
if self.debug:
|
||||||
randomPort = 8080
|
randomPort = 8080
|
||||||
else:
|
else:
|
||||||
randomPort = random.randint(1024, 65535)
|
randomPort = random.randint(1024, 65535)
|
||||||
|
Loading…
Reference in New Issue
Block a user