Skip to content

Commit 564bcde

Browse files
committed
Server updates
1 parent 1094108 commit 564bcde

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

server/server.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# import sys
2-
# sys.path.append('./dist')
3-
1+
import os
42
import json
53
import asyncio
64
import logging
@@ -113,6 +111,7 @@ async def graphql_api(request: web.Request) -> web.Response:
113111
async def graphql_api_options(_: web.Request) -> web.Response:
114112
return web.json_response({"message": "Accept all hosts"}, headers=HEADERS)
115113

114+
# Proxy route
116115
# @routes.route("*", "/{tail:.*}")
117116
# async def proxy(request: web.Request) -> web.Response:
118117
# async with ClientSession() as session:
@@ -131,20 +130,35 @@ async def graphql_api_options(_: web.Request) -> web.Response:
131130
# Server index.html file
132131
@routes.get('/')
133132
async def index(request: web.Request):
134-
return web.FileResponse('index.html')
133+
if os.path.exists('assets'):
134+
return web.FileResponse('index.html')
135+
else:
136+
return web.FileResponse('dist/index.html')
135137

136138
# Web App initialization
137139
app = web.Application()
138140
app.add_routes(routes)
139141

142+
if os.path.exists('assets'):
143+
print('Using assets static path')
144+
app.add_routes([web.static('/', './')])
145+
routes.static('/', './')
146+
else:
147+
print('Using dist static path')
148+
app.add_routes([web.static('/', 'dist')])
149+
routes.static('/', 'dist')
150+
140151
def run_app():
141-
logging.basicConfig(level=logging.WARNING)
142-
asyncio.get_event_loop().set_debug(enabled=True)
143-
web.run_app(app, host='localhost', port=1212, shutdown_timeout=1)
152+
logging.basicConfig(level=logging.DEBUG)
153+
loop = asyncio.new_event_loop()
154+
loop.set_debug(enabled=True)
155+
web.run_app(app, host='flow.localhost', port=1212, shutdown_timeout=1)
144156

145157
# Run the app
146158
print(__name__)
147-
if __name__ == '__main__' or __name__ == 'server.server':
159+
print(os.getcwd())
160+
print("Asset path: ", os.path.exists('assets'))
161+
if __name__ == '__main__':
148162
logging.basicConfig(level=logging.DEBUG)
149163
asyncio.get_event_loop().set_debug(enabled=True)
150164
web.run_app(app, host='localhost', port=1212, shutdown_timeout=1)

0 commit comments

Comments
 (0)