1
- # import sys
2
- # sys.path.append('./dist')
3
-
1
+ import os
4
2
import json
5
3
import asyncio
6
4
import logging
@@ -113,6 +111,7 @@ async def graphql_api(request: web.Request) -> web.Response:
113
111
async def graphql_api_options (_ : web .Request ) -> web .Response :
114
112
return web .json_response ({"message" : "Accept all hosts" }, headers = HEADERS )
115
113
114
+ # Proxy route
116
115
# @routes.route("*", "/{tail:.*}")
117
116
# async def proxy(request: web.Request) -> web.Response:
118
117
# async with ClientSession() as session:
@@ -131,20 +130,35 @@ async def graphql_api_options(_: web.Request) -> web.Response:
131
130
# Server index.html file
132
131
@routes .get ('/' )
133
132
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' )
135
137
136
138
# Web App initialization
137
139
app = web .Application ()
138
140
app .add_routes (routes )
139
141
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
+
140
151
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 )
144
156
145
157
# Run the app
146
158
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__' :
148
162
logging .basicConfig (level = logging .DEBUG )
149
163
asyncio .get_event_loop ().set_debug (enabled = True )
150
164
web .run_app (app , host = 'localhost' , port = 1212 , shutdown_timeout = 1 )
0 commit comments