I am a little struggling with getting CherryPy to both host static files and my REST api. I want the API to be on http://127.0.0.1:8080/api
, and any static files on http://127.0.0.1:8080/
. When a user just GET
s the /api
URL, I want it to serve a static HTML with a manual on how to use the API. The static html on the /
URL is a HTML5 app; a base implementation of the REST API.
What I have for now is this:
cherrypy.config.update({"tools.staticdir.on": True })
cherrypy.config.update({"tools.staticdir.dir": "/home/bart/html" })
#cherrypy.config.update({"tools.staticdir.index": "index.html"})
if __name__ == '__main__':
cherrypy.tree.mount(myApp(), "/api")
cherrypy.engine.start()
cherrypy.engine.block()
And it is almost there, except when I GET http://127.0.0.1:8080/api
, it serves the same as on /
. The index
of the myApp()
class is as follows:
@cherrypy.expose
def index(self):
# TODO: place API docs here
if cherrypy.request.method == "GET":
return "REST API v{v}".format(v=VERSION)
else:
return result(405)