-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrun.py
40 lines (31 loc) · 1.01 KB
/
run.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
from flask import Flask, request, send_from_directory
import os
import socket
# 192.168.43.212
def get_ip_address():
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
return s.getsockname()[0]
cwd = os.getcwd()
app = Flask(__name__, static_url_path = '', static_folder = cwd+'/web/')
def get_str_from_resource(rsc):
page = ''
with open('web/'+rsc, 'r') as f:
page = f.read()
return page
@app.route("/", methods=['GET', 'POST'])
def main():
if request.method == 'POST':
return "Teste de post no servidor"
if request.method == 'GET':
return get_str_from_resource('index.html')
@app.route("/<path>")
def resources(path):
if 'css' in path or 'js' in path or 'html' in path:
return get_str_from_resource(path)
return get_str_from_resource('index.html')
if __name__ == "__main__":
ip_address = get_ip_address()
if not ip_address:
ip_address = '127.0.0.0'
app.run(debug=True, host=ip_address,port=8000,threaded=True)