diff --git a/index.js b/index.js index 17dbce34b..30b248bb5 100644 --- a/index.js +++ b/index.js @@ -13,7 +13,6 @@ const template = require('./middleware/template'); const favicon = require('koa-favicon'); const debug = require('./middleware/debug'); const accessControl = require('./middleware/access-control'); -const auth = require('./middleware/auth'); const router = require('./router'); const protected_router = require('./protected_router'); @@ -40,9 +39,6 @@ app.use(favicon(__dirname + '/favicon.png')); // global error handing app.use(onerror); -// HTTP basic authentication -app.use(auth); - // 1 set header app.use(header); diff --git a/middleware/auth.js b/middleware/auth.js deleted file mode 100644 index b3a752046..000000000 --- a/middleware/auth.js +++ /dev/null @@ -1,31 +0,0 @@ -const logger = require('../utils/logger'); -const Raven = require('raven'); -const config = require('../config'); - -if (config.sentry) { - Raven.config(config.sentry).install(); -} - -module.exports = async (ctx, next) => { - try { - await next(); - } catch (err) { - if (err.status === 401) { - logger.error('Authentication error: ' + (err instanceof Error ? err.stack : err)); - ctx.set('WWW-Authenticate', 'Basic'); - ctx.body = 'RSSHub: Unauthenticated access.'; - ctx.status = 401; - if (config.sentry) { - Raven.captureException( - err, - { - req: ctx.req, - }, - function(err, eventId) { - console.log('Authentication error ' + eventId); - } - ); - } - } - } -}; diff --git a/middleware/onerror.js b/middleware/onerror.js index a468383c3..2d58617e5 100644 --- a/middleware/onerror.js +++ b/middleware/onerror.js @@ -7,6 +7,7 @@ if (config.sentry) { } module.exports = async (ctx, next) => { + console.log(123); try { await next(); } catch (err) { @@ -15,7 +16,11 @@ module.exports = async (ctx, next) => { 'Content-Type': 'text/html; charset=UTF-8', }); ctx.body = `RSSHub 发生了一些意外:
${err instanceof Error ? err.stack : err}
`; - ctx.status = 404; + if (err.status === 401) { + ctx.status = 401; + } else { + ctx.status = 404; + } if (config.sentry) { Raven.captureException(