Modulize
This commit is contained in:
parent
d73a6b7730
commit
89368d224e
2 changed files with 9 additions and 11 deletions
|
@ -1,18 +1,11 @@
|
||||||
from sanic import Sanic
|
from sanic import Sanic
|
||||||
from sanic.response import json, text
|
from lantern.route import main_route
|
||||||
from sanic.exceptions import NotFound
|
|
||||||
|
|
||||||
app = Sanic()
|
app = Sanic()
|
||||||
|
|
||||||
@app.route("/")
|
|
||||||
async def test(request):
|
|
||||||
return json({"hello": "world"})
|
|
||||||
|
|
||||||
|
|
||||||
@app.exception(NotFound)
|
|
||||||
def ignore_404s(request, exception):
|
|
||||||
return text("Page not found at {}".format(request.url), status=404)
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
app.add_route(main_route, "/<path>")
|
||||||
|
app.add_route(main_route, "/")
|
||||||
app.run(host="0.0.0.0", port="8000")
|
app.run(host="0.0.0.0", port="8000")
|
||||||
|
|
5
lantern/route.py
Normal file
5
lantern/route.py
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
from sanic.response import json
|
||||||
|
|
||||||
|
|
||||||
|
async def main_route(request, path=None):
|
||||||
|
return json({"hello": "world"})
|
Reference in a new issue