diff --git a/server/index.ts b/server/index.ts index f5b41c590f..49e549e765 100644 --- a/server/index.ts +++ b/server/index.ts @@ -6,7 +6,7 @@ import "./logging/tracer"; // must come before importing any instrumented module import http from "http"; import https from "https"; -import Koa from "koa"; +import Koa, { Context } from "koa"; import helmet from "koa-helmet"; import logger from "koa-logger"; import Router from "koa-router"; @@ -90,6 +90,7 @@ async function start(_id: number, disconnect: () => void) { /** Perform a redirect on the browser so that the user's auth cookies are included in the request. */ app.context.redirectOnClient = function ( + this: Context, /** The URL to redirect to */ url: string, /** @@ -113,6 +114,13 @@ async function start(_id: number, disconnect: () => void) { )}" value="${escape(value)}" />`; }); + if (this.userAgent.isBot) { + formFields += ` +

If you are not redirected automatically, please click the button below.

+ + `; + } + this.body = ` @@ -123,7 +131,7 @@ async function start(_id: number, disconnect: () => void) { ${formFields} `; diff --git a/server/routes/index.ts b/server/routes/index.ts index 26fbded27d..81f719b6ee 100644 --- a/server/routes/index.ts +++ b/server/routes/index.ts @@ -1,10 +1,9 @@ import crypto from "crypto"; import path from "path"; import { formatRFC7231 } from "date-fns"; -import Koa, { BaseContext } from "koa"; +import Koa from "koa"; import Router from "koa-router"; import send from "koa-send"; -import userAgent, { UserAgentContext } from "koa-useragent"; import { languages } from "@shared/i18n"; import { IntegrationType, TeamPreference } from "@shared/types"; import { parseDomain } from "@shared/utils/domains"; @@ -24,8 +23,6 @@ import errors from "./errors"; const koa = new Koa(); const router = new Router(); -koa.use(userAgent); - // serve public assets router.use(["/images/*", "/email/*", "/fonts/*"], async (ctx, next) => { let done; diff --git a/server/services/web.ts b/server/services/web.ts index b6a29a7d80..69edb5de05 100644 --- a/server/services/web.ts +++ b/server/services/web.ts @@ -1,6 +1,6 @@ /* oxlint-disable @typescript-eslint/no-var-requires */ import { Server } from "https"; -import Koa from "koa"; +import Koa, { BaseContext } from "koa"; import compress from "koa-compress"; import { dnsPrefetchControl, referrerPolicy } from "koa-helmet"; import mount from "koa-mount"; @@ -20,6 +20,7 @@ import routes from "../routes"; import api from "../routes/api"; import auth from "../routes/auth"; import oauth from "../routes/oauth"; +import userAgent, { UserAgentContext } from "koa-useragent"; export default function init(app: Koa = new Koa(), server?: Server) { void initI18n(); @@ -45,6 +46,9 @@ export default function init(app: Koa = new Koa(), server?: Server) { app.proxy = true; } + // Make `ctx.userAgent` available + app.use(userAgent); + app.use(compress()); // Monitor server connections