From 6994549360a16a287de32c49f244062898e905ac Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Sun, 1 Mar 2015 19:05:50 +0300 Subject: [PATCH] + 404 page --- assets/style/error-404.scss | 15 +++++++++++++++ client/app.js | 2 +- routes/404.js | 31 +++++++++++++++++++++++++++++++ server.js | 2 ++ templates/404.html | 4 ++++ 5 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 assets/style/error-404.scss create mode 100644 routes/404.js create mode 100644 templates/404.html diff --git a/assets/style/error-404.scss b/assets/style/error-404.scss new file mode 100644 index 00000000..5083c8f2 --- /dev/null +++ b/assets/style/error-404.scss @@ -0,0 +1,15 @@ +.error-404{ + text-align: center; + margin: 40px; + + h1{ + font-size: 16pt; + font-weight: normal; + } + + img{ + margin: 20px; + width: 40%; + max-width: 800px; + } +} \ No newline at end of file diff --git a/client/app.js b/client/app.js index af45ee89..db1e1e1b 100644 --- a/client/app.js +++ b/client/app.js @@ -45,7 +45,7 @@ app.config(function ($locationProvider, $routeProvider) { }); $routeProvider.otherwise({ - redirectTo: "/" + templateUrl: "/404.html" }); }); diff --git a/routes/404.js b/routes/404.js new file mode 100644 index 00000000..1421865d --- /dev/null +++ b/routes/404.js @@ -0,0 +1,31 @@ +/** + * Created by tmshv on 01/03/15. + */ + +var route = require("koa-route"); +var router = require("./"); + +module.exports = function (app) { + app.use(function *(next) { + yield next; + + if (404 != this.status) return; + + this.status = 404; + yield router.accepts({ + "text/html": router.index(), + + "text/plain": function *() { + this.type = "text/plain"; + this.body = "Page not found"; + }, + + "application/json": function *() { + this.type = "application/json"; + this.body = { + message: "Not Found" + }; + } + }); + }); +}; \ No newline at end of file diff --git a/server.js b/server.js index d24e9e7e..25154cbe 100644 --- a/server.js +++ b/server.js @@ -53,6 +53,8 @@ app.use(route.get("/document/:doc", routes.index( require("./routes/schedule")(app); require("./routes/news")(app); +require("./routes/404")(app); + if (process.env["NODE_ENV"] === "development") { app.use(route.get("/debug", function *() { var out = {}; diff --git a/templates/404.html b/templates/404.html new file mode 100644 index 00000000..75ad0500 --- /dev/null +++ b/templates/404.html @@ -0,0 +1,4 @@ +
+

Страница не найдена.

+ +
\ No newline at end of file