python - How to serve a static webpage from falcon application? -


i new python , hence falcon. started developing restful api , falcon far great it. there other requirement serve static web page , dont want write app or spawn server that.

is possible falcon app serve static web page?

first , important, have don't want that. should have nginx server on top of falcon app, , serve static file directly nginx (and redirect api calls falcon).

this being said, can serve static files falcon. code looking for:

import falcon   class staticresource(object):     def on_get(self, req, resp):         resp.status = falcon.http_200         resp.content_type = 'text/html'         open('index.html', 'r') f:             resp.body = f.read()  app = falcon.api() app.add_route('/', staticresource()) 

you may want set file name parameter in url, , in resource, static resource can serve requested file directory.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -