From 98c6f7a445c345d0aa967cfcbac485016e11aa8f Mon Sep 17 00:00:00 2001 From: Isaac Date: Wed, 7 Sep 2022 22:15:46 +0100 Subject: [PATCH] fix http logging spam, and login loop --- README.md | 2 ++ src/http.js | 12 +++++++++--- src/routes/auth/callback.js | 4 +++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1b30c1d..2251cd4 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ https://www.prisma.io/docs/reference/database-reference/supported-databases menu question max length cannot be higher than question options +ports <1024 require root + - TODO: topic and question answer values not encrypted? - TODO: post stats - TODO: settings bundle download diff --git a/src/http.js b/src/http.js index 30355b8..e216246 100644 --- a/src/http.js +++ b/src/http.js @@ -1,5 +1,6 @@ const fastify = require('fastify')(); const oauth = require('@fastify/oauth2'); +const { domain } = require('./lib/http'); const { short } = require('leeks.js'); const { join } = require('path'); const { files } = require('node-dir'); @@ -45,6 +46,12 @@ module.exports = async client => { fastify.register(require('@fastify/http-proxy'), { http2: false, prefix: '/settings', + replyOptions: { + rewriteRequestHeaders: (req, headers) => ({ + ...headers, + 'host': domain, + }), + }, rewritePrefix: '/settings', upstream: `http://127.0.0.1:${process.env.SETTINGS_BIND}`, }); @@ -62,8 +69,6 @@ module.exports = async client => { }); } } catch (err) { - console.log(req); - console.log(req.cookies); res.send(err); } }); @@ -126,7 +131,8 @@ module.exports = async client => { : responseTime >= 5 ? '&e' : '&a') + responseTime + 'ms'; - client.log.info.http(short(`${req.id} ${req.ip} ${req.method} ${req.routerPath ?? '*'} &m-+>&r ${status}&b in ${responseTime}`)); + const level = req.routerPath.startsWith('/settings') ? 'verbose' : 'info'; + client.log[level].http(short(`${req.id} ${req.ip} ${req.method} ${req.routerPath ?? '*'} &m-+>&r ${status}&b in ${responseTime}`)); if (!req.routerPath) client.log.verbose.http(`${req.id} ${req.method} ${req.url}`); done(); }); diff --git a/src/routes/auth/callback.js b/src/routes/auth/callback.js index 328d3a8..fccb57c 100644 --- a/src/routes/auth/callback.js +++ b/src/routes/auth/callback.js @@ -23,6 +23,8 @@ module.exports.get = () => ({ sameSite: true, secure: false, }) - .redirect('/settings'); + // .redirect('/settings') + .type('text/html') + .send('/settings'); // temp fix: redirecting causes weird discord<->callback loop, probably caching? }, }); \ No newline at end of file