From f2185c5f8c2fb5384e5db344a759820eb0c51202 Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Wed, 24 Feb 2016 18:35:28 +0300 Subject: [PATCH] 404 ES6 refactoring, export signature change --- src/routes/404.js | 29 ++++++++++++----------------- src/server.js | 4 ++-- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/routes/404.js b/src/routes/404.js index 1421865d..8f706ce0 100644 --- a/src/routes/404.js +++ b/src/routes/404.js @@ -1,31 +1,26 @@ -/** - * Created by tmshv on 01/03/15. - */ +import {index, accepts} from './'; -var route = require("koa-route"); -var router = require("./"); - -module.exports = function (app) { - app.use(function *(next) { +export default function () { + return function *(next) { yield next; if (404 != this.status) return; this.status = 404; - yield router.accepts({ - "text/html": router.index(), + yield accepts({ + 'text/html': index(), - "text/plain": function *() { - this.type = "text/plain"; - this.body = "Page not found"; + 'text/plain': function *() { + this.type = 'text/plain'; + this.body = 'Page not found'; }, - "application/json": function *() { - this.type = "application/json"; + 'application/json': function *() { + this.type = 'application/json'; this.body = { - message: "Not Found" + message: 'Not Found' }; } }); - }); + }; }; \ No newline at end of file diff --git a/src/server.js b/src/server.js index b475f3c4..88e8c706 100644 --- a/src/server.js +++ b/src/server.js @@ -18,7 +18,7 @@ import news from './routes/news'; import gallery from './routes/gallery'; import instagram from './instagram/router'; import instagramIO from './instagram/io'; -import e404 from './routes/404'; +import error404 from './routes/404'; import documents from './routes/documents'; import collective from './routes/collective'; @@ -52,6 +52,6 @@ news(app); gallery(app); instagram(app); instagramIO(app); -e404(app); documents(app); collective(app); +app.use(error404()); \ No newline at end of file