From a5298ecff9319a77f09c9ce602b52a04011329d6 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Sat, 12 Mar 2016 15:46:38 -0600 Subject: [PATCH] 404 error for flask api. --- ctf.nginx | 2 +- server/api/user.py | 2 +- server/app.py | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ctf.nginx b/ctf.nginx index 7726e44..15548a5 100644 --- a/ctf.nginx +++ b/ctf.nginx @@ -7,7 +7,7 @@ server { index index.html index.htm; server_name localhost; - error_page 404 /404; + error_page 404 /index.html; # location / { # try_files $uri $uri/ =404; diff --git a/server/api/user.py b/server/api/user.py index ce3e212..a3e82c3 100644 --- a/server/api/user.py +++ b/server/api/user.py @@ -1,4 +1,4 @@ -from flask import Blueprint, make_response, session, request, redirect, url_for, send_file +from flask import Blueprint, make_response, session, request, redirect, url_for, send_file, abort from werkzeug import secure_filename from flask import current_app as app from voluptuous import Schema, Length, Required diff --git a/server/app.py b/server/app.py index f6378d3..1f10876 100644 --- a/server/app.py +++ b/server/app.py @@ -1,7 +1,7 @@ #!/usr/bin/python from argparse import ArgumentParser -from flask import Flask +from flask import Flask, send_file app = Flask(__name__) @@ -40,6 +40,10 @@ api.logger.initialize_logs() def api_main(): return { "success": 1, "message": "The API is online." } +@app.errorhandler(404) +def page_not_found(e): + return send_file("../web/index.html") + def run(args): with app.app_context(): keyword_args = dict(args._get_kwargs())