mirror of
https://github.com/outline/outline.git
synced 2026-11-26 15:43:48 +03:00
chore: Replace deprecated koa-router with @koa/router v15 (#14042)
* chore: Replace deprecated koa-router with @koa/router v15 * fix: Run optional authentication on all auth provider routes
This commit is contained in:
1 parent
97103c0247
commit
086bd9e9e4
69 files changed
+155
-166
No files matched your search
+1
-2
@@ -81,6 +81,7 @@
|
||||
"@hocuspocus/provider": "1.1.3",
|
||||
"@hocuspocus/server": "1.1.3",
|
||||
"@juggle/resize-observer": "^3.4.0",
|
||||
"@koa/router": "^15.7.0",
|
||||
"@linear/sdk": "^97.0.0",
|
||||
"@mermaid-js/layout-elk": "0.2.2",
|
||||
"@modelcontextprotocol/sdk": "^1.31.0",
|
||||
@@ -168,7 +169,6 @@
|
||||
"koa-helmet": "^6.1.0",
|
||||
"koa-logger": "^3.2.1",
|
||||
"koa-mount": "^4.2.0",
|
||||
"koa-router": "7.4.0",
|
||||
"koa-send": "5.0.1",
|
||||
"koa-sslify": "5.0.1",
|
||||
"koa-useragent": "^4.1.0",
|
||||
@@ -308,7 +308,6 @@
|
||||
"@types/koa-compress": "^4.0.7",
|
||||
"@types/koa-logger": "^3.1.5",
|
||||
"@types/koa-mount": "^4.0.5",
|
||||
"@types/koa-router": "^7.4.9",
|
||||
"@types/koa-send": "^4.1.6",
|
||||
"@types/koa-sslify": "^4.0.6",
|
||||
"@types/koa-useragent": "^2.1.2",
|
||||
|
||||
@@ -2,7 +2,7 @@ import passport from "@outlinewiki/koa-passport";
|
||||
import { Strategy as AzureStrategy } from "@outlinewiki/passport-azure-ad-oauth2";
|
||||
import jwt from "jsonwebtoken";
|
||||
import type { Request } from "koa";
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import type { Profile } from "passport";
|
||||
import { toError } from "@shared/utils/error";
|
||||
import { slugifyDomain } from "@shared/utils/domains";
|
||||
|
||||
@@ -6,7 +6,7 @@ import type {
|
||||
RESTGetCurrentUserGuildMemberResult,
|
||||
} from "discord-api-types/v10";
|
||||
import type { Request } from "koa";
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
|
||||
import { Strategy } from "passport-oauth2";
|
||||
import { toError } from "@shared/utils/error";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import { errToString } from "@shared/utils/error";
|
||||
import { Client, NotificationEventType } from "@shared/types";
|
||||
import { parseDomain } from "@shared/utils/domains";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { toError } from "@shared/utils/error";
|
||||
import auth from "@server/middlewares/authentication";
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import * as T from "./schema";
|
||||
import apexAuthRedirect from "@server/middlewares/apexAuthRedirect";
|
||||
import type { APIContext } from "@server/types";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import { find } from "es-toolkit/compat";
|
||||
import { IntegrationService, IntegrationType } from "@shared/types";
|
||||
import { createContext } from "@server/context";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import { Op } from "sequelize";
|
||||
import { toError } from "@shared/utils/error";
|
||||
import { IntegrationService, IntegrationType } from "@shared/types";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import passport from "@outlinewiki/koa-passport";
|
||||
import type { Request } from "koa";
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import { capitalize } from "es-toolkit/compat";
|
||||
import type { Profile } from "passport";
|
||||
import { Strategy as GoogleStrategy } from "passport-google-oauth2";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import { toError } from "@shared/utils/error";
|
||||
import { IntegrationService, IntegrationType } from "@shared/types";
|
||||
import { ValidationError } from "@server/errors";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import { IntegrationService, IntegrationType } from "@shared/types";
|
||||
import { ValidationError } from "@server/errors";
|
||||
import apexAuthRedirect from "@server/middlewares/apexAuthRedirect";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import { toError } from "@shared/utils/error";
|
||||
import Logger from "@server/logging/Logger";
|
||||
import env from "../env";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import passport from "@outlinewiki/koa-passport";
|
||||
import JWT from "jsonwebtoken";
|
||||
import type { Context, Request } from "koa";
|
||||
import type Router from "koa-router";
|
||||
import type Router from "@koa/router";
|
||||
import { get } from "es-toolkit/compat";
|
||||
import { toError } from "@shared/utils/error";
|
||||
import { slugifyDomain } from "@shared/utils/domains";
|
||||
|
||||
@@ -3,7 +3,7 @@ import validate from "@server/middlewares/validate";
|
||||
import { UserPasskey } from "@server/models";
|
||||
import type { APIContext } from "@server/types";
|
||||
import { AuthenticationType } from "@server/types";
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import * as T from "./schema";
|
||||
import { authorize } from "@server/policies";
|
||||
import { transaction } from "@server/middlewares/transaction";
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
} from "@simplewebauthn/server";
|
||||
import { isoBase64URL } from "@simplewebauthn/server/helpers";
|
||||
import type { AuthenticatorTransportFuture } from "@simplewebauthn/server";
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import { randomBytes } from "node:crypto";
|
||||
import { toError } from "@shared/utils/error";
|
||||
import { User, UserPasskey, Team } from "@server/models";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { t } from "i18next";
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import { escapeRegExp } from "es-toolkit/compat";
|
||||
import queryString from "query-string";
|
||||
import { z } from "zod";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import passport from "@outlinewiki/koa-passport";
|
||||
import type { Request } from "koa";
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import type { Profile } from "passport";
|
||||
import { Strategy as SlackStrategy } from "passport-slack-oauth2";
|
||||
import { toError } from "@shared/utils/error";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import JWT from "jsonwebtoken";
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import mime from "mime-types";
|
||||
import contentDisposition from "content-disposition";
|
||||
import { bytesToHumanReadable } from "@shared/utils/files";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import { compact, isEmpty } from "es-toolkit/compat";
|
||||
import { Op, Sequelize, type WhereOptions } from "sequelize";
|
||||
import { UserRole } from "@shared/types";
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import type { AddressInfo } from "node:net";
|
||||
import Koa from "koa";
|
||||
import helmet from "koa-helmet";
|
||||
import logger from "koa-logger";
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import stoppable from "stoppable";
|
||||
import { toError } from "@shared/utils/error";
|
||||
import env from "./env";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import auth from "@server/middlewares/authentication";
|
||||
import { rateLimiter } from "@server/middlewares/rateLimiter";
|
||||
import { transaction } from "@server/middlewares/transaction";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import { Op, Sequelize, type WhereOptions } from "sequelize";
|
||||
import auth from "@server/middlewares/authentication";
|
||||
import { rateLimiter } from "@server/middlewares/rateLimiter";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import type { WhereOptions } from "sequelize";
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { AttachmentPreset } from "@shared/types";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { subHours, subMinutes } from "date-fns";
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import { uniqBy } from "es-toolkit/compat";
|
||||
import { TeamPreference } from "@shared/types";
|
||||
import { parseDomain } from "@shared/utils/domains";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import { UserRole } from "@shared/types";
|
||||
import env from "@server/env";
|
||||
import { InvalidRequestError } from "@server/errors";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { chunk, omit, snakeCase } from "es-toolkit/compat";
|
||||
import type { Middleware } from "koa";
|
||||
import compose from "koa-compose";
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import auth from "@server/middlewares/authentication";
|
||||
import {
|
||||
defaultRateLimiter,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { truncate } from "es-toolkit/compat";
|
||||
import type { WhereOptions } from "sequelize";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import { difference } from "es-toolkit/compat";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { MentionType, IconType } from "@shared/types";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import env from "@server/env";
|
||||
import { AuthenticationError } from "@server/errors";
|
||||
import Logger from "@server/logging/Logger";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { Context, Next } from "koa";
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import { Op } from "sequelize";
|
||||
import { randomString, randomElement } from "@shared/random";
|
||||
import { NotificationEventType } from "@shared/types";
|
||||
|
||||
@@ -3,7 +3,7 @@ import fractionalIndex from "fractional-index";
|
||||
import fs from "fs-extra";
|
||||
import invariant from "invariant";
|
||||
import contentDisposition from "content-disposition";
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import { escapeRegExp, has, remove, uniq } from "es-toolkit/compat";
|
||||
import mime from "mime-types";
|
||||
import type { Order, ScopeOptions, WhereOptions } from "sequelize";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import type { WhereOptions } from "sequelize";
|
||||
import { Op } from "sequelize";
|
||||
import auth from "@server/middlewares/authentication";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import { intersection } from "es-toolkit/compat";
|
||||
import type { WhereOptions } from "sequelize";
|
||||
import { Op } from "sequelize";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import type { WhereOptions } from "sequelize";
|
||||
import { UserRole } from "@shared/types";
|
||||
import { ValidationError } from "@server/errors";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import { uniqBy } from "es-toolkit/compat";
|
||||
import { Op } from "sequelize";
|
||||
import auth from "@server/middlewares/authentication";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { compact, uniqBy } from "es-toolkit";
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import type { WhereOptions } from "sequelize";
|
||||
import { Op } from "sequelize";
|
||||
import { MAX_AVATAR_DISPLAY } from "@shared/constants";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { truncate } from "es-toolkit/compat";
|
||||
import type { WhereOptions } from "sequelize";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { BaseContext } from "koa";
|
||||
import Koa from "koa";
|
||||
import bodyParser from "koa-body";
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import type { UserAgentContext } from "koa-useragent";
|
||||
import userAgent from "koa-useragent";
|
||||
import env from "@server/env";
|
||||
@@ -133,11 +133,11 @@ if (env.isDevelopment) {
|
||||
router.use("/", developer.routes());
|
||||
}
|
||||
|
||||
router.register("*", ["get", "post"], (ctx) => {
|
||||
router.register("{/*path}", ["get", "post"], (ctx) => {
|
||||
ctx.throw(NotFoundError("Endpoint not found"));
|
||||
});
|
||||
|
||||
// Router is embedded in a Koa application wrapper, because koa-router does not
|
||||
// Router is embedded in a Koa application wrapper, because @koa/router does not
|
||||
// allow middleware to catch any routes which were not explicitly defined.
|
||||
api.use(router.routes());
|
||||
api.use(router.allowedMethods());
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import { Client, UserRole } from "@shared/types";
|
||||
import teamCreator from "@server/commands/teamCreator";
|
||||
import { ValidationError } from "@server/errors";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import type { WhereOptions } from "sequelize";
|
||||
import { Op } from "sequelize";
|
||||
import { IntegrationType, UserRole } from "@shared/types";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import { isEmpty, isNil, isNull, isUndefined } from "es-toolkit/compat";
|
||||
import type { WhereOptions } from "sequelize";
|
||||
import { Op } from "sequelize";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import { QueryTypes } from "sequelize";
|
||||
import auth from "@server/middlewares/authentication";
|
||||
import { rateLimiter } from "@server/middlewares/rateLimiter";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import { Op } from "sequelize";
|
||||
import AuthenticationHelper from "@shared/helpers/AuthenticationHelper";
|
||||
import { UserRole } from "@shared/types";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import { Sequelize, Op, Transaction } from "sequelize";
|
||||
import pinCreator from "@server/commands/pinCreator";
|
||||
import auth from "@server/middlewares/authentication";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import type { WhereOptions } from "sequelize";
|
||||
import auth from "@server/middlewares/authentication";
|
||||
import validate from "@server/middlewares/validate";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import { InvalidRequestError } from "@server/errors";
|
||||
import auth from "@server/middlewares/authentication";
|
||||
import validate from "@server/middlewares/validate";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import path from "node:path";
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import contentDisposition from "content-disposition";
|
||||
import { escapeRegExp } from "es-toolkit/compat";
|
||||
import mime from "mime-types";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import auth from "@server/middlewares/authentication";
|
||||
import { transaction } from "@server/middlewares/transaction";
|
||||
import validate from "@server/middlewares/validate";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import { isUndefined } from "es-toolkit/compat";
|
||||
import type { FindOptions, WhereAttributeHash, WhereOptions } from "sequelize";
|
||||
import { Op } from "sequelize";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import { Sequelize } from "sequelize";
|
||||
import starCreator from "@server/commands/starCreator";
|
||||
import auth from "@server/middlewares/authentication";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import type { WhereOptions } from "sequelize";
|
||||
import { Transaction } from "sequelize";
|
||||
import { QueryNotices } from "@shared/types";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import { Op } from "sequelize";
|
||||
import { Sequelize } from "sequelize-typescript";
|
||||
import auth from "@server/middlewares/authentication";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import { UserRole } from "@shared/types";
|
||||
import teamCreator from "@server/commands/teamCreator";
|
||||
import teamUpdater from "@server/commands/teamUpdater";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import type { WhereOptions } from "sequelize";
|
||||
import { Op, Sequelize } from "sequelize";
|
||||
import { ProsemirrorDataHelper } from "@shared/utils/ProsemirrorDataHelper";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import dns from "node:dns";
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import { traceFunction } from "@server/logging/tracing";
|
||||
import isUUID from "validator/lib/isUUID";
|
||||
import { MentionType, UnfurlResourceType } from "@shared/types";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import { Op, Sequelize } from "sequelize";
|
||||
import auth from "@server/middlewares/authentication";
|
||||
import { transaction } from "@server/middlewares/transaction";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import type { WhereOptions } from "sequelize";
|
||||
import { Op, Sequelize } from "sequelize";
|
||||
import { NotificationEventType, UserRole } from "@shared/types";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import { ValidationError } from "@server/errors";
|
||||
import auth from "@server/middlewares/authentication";
|
||||
import { rateLimiter } from "@server/middlewares/rateLimiter";
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
import { addMonths } from "date-fns";
|
||||
import { buildUser, buildCollection } from "@server/test/factories";
|
||||
import { getTestServer } from "@server/test/support";
|
||||
import {
|
||||
getTestServer,
|
||||
setCloudHosted,
|
||||
setSelfHosted,
|
||||
} from "@server/test/support";
|
||||
import { getJWTPayload } from "@server/utils/jwt";
|
||||
import { verifyOAuthState } from "@server/utils/oauthState";
|
||||
|
||||
const server = getTestServer();
|
||||
|
||||
@@ -73,3 +78,23 @@ describe("auth/redirect", () => {
|
||||
expect(res.status).toEqual(401);
|
||||
});
|
||||
});
|
||||
|
||||
describe("auth provider routes", () => {
|
||||
beforeEach(setSelfHosted);
|
||||
afterEach(setCloudHosted);
|
||||
|
||||
it("should include the signed-in actor in the OAuth state", async () => {
|
||||
const user = await buildUser();
|
||||
const res = await server.get("/auth/google", {
|
||||
redirect: "manual",
|
||||
headers: {
|
||||
Cookie: `accessToken=${user.getSessionToken()}`,
|
||||
},
|
||||
});
|
||||
expect(res.status).toEqual(302);
|
||||
|
||||
const location = new URL(res.headers.get("location") ?? "");
|
||||
const state = verifyOAuthState(location.searchParams.get("state") ?? "");
|
||||
expect(state.actorId).toEqual(user.id);
|
||||
});
|
||||
});
|
||||
@@ -2,7 +2,7 @@ import passport from "@outlinewiki/koa-passport";
|
||||
import { addMonths } from "date-fns";
|
||||
import Koa from "koa";
|
||||
import bodyParser from "koa-body";
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import { AuthenticationError } from "@server/errors";
|
||||
import authMiddleware from "@server/middlewares/authentication";
|
||||
import coalesceBody from "@server/middlewares/coaleseBody";
|
||||
@@ -20,14 +20,16 @@ router.use(passport.initialize());
|
||||
|
||||
// dynamically register available authentication provider routes
|
||||
void (async () => {
|
||||
for (const provider of AuthenticationHelper.providers) {
|
||||
const resolvedRouter = await provider.value.router;
|
||||
const resolvedRouters = await Promise.all(
|
||||
AuthenticationHelper.providers.map((provider) =>
|
||||
Promise.resolve(provider.value.router)
|
||||
)
|
||||
);
|
||||
|
||||
router.use(authMiddleware({ optional: true }));
|
||||
for (const resolvedRouter of resolvedRouters) {
|
||||
if (resolvedRouter) {
|
||||
router.use(
|
||||
"/",
|
||||
authMiddleware({ optional: true }),
|
||||
resolvedRouter.routes()
|
||||
);
|
||||
router.use("/", resolvedRouter.routes());
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import { Day } from "@shared/utils/time";
|
||||
import { opensearchResponse } from "./opensearch";
|
||||
import { robotsResponse } from "./robots";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import { TeamPreference } from "@shared/types";
|
||||
import env from "@server/env";
|
||||
import { OAuthHelper } from "@server/utils/oauth/OAuthHelper";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
|
||||
const router = new Router();
|
||||
|
||||
|
||||
+31
-24
@@ -2,7 +2,7 @@ import crypto from "node:crypto";
|
||||
import path from "node:path";
|
||||
import { formatRFC7231 } from "date-fns";
|
||||
import Koa from "koa";
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import send from "koa-send";
|
||||
import { languages } from "@shared/i18n";
|
||||
import { TeamPreference } from "@shared/types";
|
||||
@@ -25,33 +25,40 @@ const koa = new Koa();
|
||||
const router = new Router();
|
||||
|
||||
// serve public assets
|
||||
router.use(["/images/*", "/email/*", "/fonts/*"], async (ctx, next) => {
|
||||
let done;
|
||||
router.use(
|
||||
["/images/{*path}", "/email/{*path}", "/fonts/{*path}"],
|
||||
async (ctx, next) => {
|
||||
let done;
|
||||
|
||||
if (ctx.method === "HEAD" || ctx.method === "GET") {
|
||||
try {
|
||||
done = await send(ctx, ctx.path, {
|
||||
root: path.resolve(__dirname, "../../../public"),
|
||||
// 7 day expiry, these assets are mostly static but do not contain a hash
|
||||
maxAge: Day.ms * 7,
|
||||
setHeaders: (res) => {
|
||||
res.setHeader("Access-Control-Allow-Origin", "*");
|
||||
},
|
||||
});
|
||||
} catch (err) {
|
||||
if (!(err instanceof Error && "status" in err && err.status === 404)) {
|
||||
throw err;
|
||||
if (ctx.method === "HEAD" || ctx.method === "GET") {
|
||||
try {
|
||||
done = await send(ctx, ctx.path, {
|
||||
root: path.resolve(__dirname, "../../../public"),
|
||||
// 7 day expiry, these assets are mostly static but do not contain a hash
|
||||
maxAge: Day.ms * 7,
|
||||
setHeaders: (res) => {
|
||||
res.setHeader("Access-Control-Allow-Origin", "*");
|
||||
},
|
||||
});
|
||||
} catch (err) {
|
||||
if (!(err instanceof Error && "status" in err && err.status === 404)) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!done) {
|
||||
await next();
|
||||
if (!done) {
|
||||
await next();
|
||||
}
|
||||
}
|
||||
});
|
||||
);
|
||||
|
||||
router.use(
|
||||
["/share/:shareId", "/share/:shareId/doc/:documentSlug", "/share/:shareId/*"],
|
||||
[
|
||||
"/share/:shareId",
|
||||
"/share/:shareId/doc/:documentSlug",
|
||||
"/share/:shareId/{*path}",
|
||||
],
|
||||
(ctx) => {
|
||||
const redirectPath = ctx.path.replace(/^\/share/, "/s");
|
||||
ctx.redirect(redirectPath + ctx.request.URL.search);
|
||||
@@ -60,7 +67,7 @@ router.use(
|
||||
);
|
||||
|
||||
if (env.isProduction) {
|
||||
router.get("/static/*", async (ctx) => {
|
||||
router.get("/static/{*path}", async (ctx) => {
|
||||
try {
|
||||
const pathname = ctx.path.substring(8);
|
||||
if (!pathname) {
|
||||
@@ -129,7 +136,7 @@ router.get(
|
||||
renderShare
|
||||
);
|
||||
router.get("/s/:shareId/doc/:documentSlug", shareDomains(), renderShare);
|
||||
router.get("/s/:shareId/*", shareDomains(), renderShare);
|
||||
router.get("/s/:shareId/{*path}", shareDomains(), renderShare);
|
||||
|
||||
router.get("/embeds/gitlab", renderEmbed);
|
||||
router.get("/embeds/github", renderEmbed);
|
||||
@@ -167,7 +174,7 @@ function isPublicAppPath(path: string) {
|
||||
}
|
||||
|
||||
// catch all for application
|
||||
router.get("*", async (ctx, next) => {
|
||||
router.get("{/*path}", async (ctx, next) => {
|
||||
if (isInvalidAppPath(ctx.path)) {
|
||||
ctx.status = 404;
|
||||
return;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import Koa from "koa";
|
||||
import bodyParser from "koa-body";
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
||||
import type { AuthInfo } from "@modelcontextprotocol/sdk/server/auth/types.js";
|
||||
import { ErrorCode } from "@modelcontextprotocol/sdk/types.js";
|
||||
@@ -144,7 +144,7 @@ router.delete("/", async (ctx) => {
|
||||
|
||||
// Clients probing for a transport we do not implement, such as the legacy
|
||||
// HTTP+SSE endpoints, must not fall through to the application shell
|
||||
router.all("*", async (ctx) => {
|
||||
router.all("{/*path}", async (ctx) => {
|
||||
ctx.status = 404;
|
||||
ctx.body = { error: "Not found. MCP requests must be sent to /mcp." };
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import OAuth2Server from "@node-oauth/oauth2-server";
|
||||
import Koa from "koa";
|
||||
import bodyParser from "koa-body";
|
||||
import Router from "koa-router";
|
||||
import Router from "@koa/router";
|
||||
import env from "@server/env";
|
||||
import { ValidationError, NotFoundError } from "@server/errors";
|
||||
import { apiContext } from "@server/middlewares/apiContext";
|
||||
|
||||
+7
-6
@@ -1,5 +1,5 @@
|
||||
import type { ParameterizedContext, DefaultContext } from "koa";
|
||||
import type { IRouterParamContext } from "koa-router";
|
||||
import type { RouterContext } from "@koa/router";
|
||||
import type { InferAttributes, Model, Transaction } from "sequelize";
|
||||
import type { z } from "zod";
|
||||
import type {
|
||||
@@ -92,11 +92,12 @@ export type BaseRes = unknown;
|
||||
export interface APIContext<
|
||||
ReqT = Partial<BaseReq>,
|
||||
ResT = BaseRes,
|
||||
> extends ParameterizedContext<
|
||||
AppState,
|
||||
DefaultContext & IRouterParamContext<AppState>,
|
||||
ResT
|
||||
> {
|
||||
> extends RouterContext<AppState, DefaultContext, ResT> {
|
||||
// Router internals are left untyped so that handlers with a narrower context
|
||||
// remain assignable to route middleware.
|
||||
router: never;
|
||||
matched?: never;
|
||||
|
||||
/** Typed and validated version of request, consisting of validated body, query, etc. */
|
||||
input: ReqT;
|
||||
|
||||
|
||||
+2
-2
@@ -15,7 +15,7 @@ declare module "@outlinewiki/koa-passport" {
|
||||
// oxlint-disable-next-line
|
||||
import Express from "express";
|
||||
import { Request } from "koa";
|
||||
import { IMiddleware } from "koa-router";
|
||||
import { RouterMiddleware } from "@koa/router";
|
||||
|
||||
namespace passport {
|
||||
interface AuthenticateOptions {
|
||||
@@ -40,7 +40,7 @@ declare module "@outlinewiki/koa-passport" {
|
||||
}
|
||||
|
||||
interface Authenticator<
|
||||
InitializeRet = IMiddleware,
|
||||
InitializeRet = RouterMiddleware,
|
||||
AuthenticateRet = any,
|
||||
AuthorizeRet = AuthenticateRet,
|
||||
AuthorizeOptions = AuthenticateOptions,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import path from "node:path";
|
||||
import { glob } from "glob";
|
||||
import type Router from "koa-router";
|
||||
import type Router from "@koa/router";
|
||||
import { isArray, sortBy } from "es-toolkit/compat";
|
||||
import type BaseEmail from "@server/emails/templates/BaseEmail";
|
||||
import env from "@server/env";
|
||||
@@ -111,7 +111,9 @@ export class PluginManager {
|
||||
Logger.debug(
|
||||
"plugins",
|
||||
`Plugin(type=${plugin.type}) registered ${
|
||||
"name" in plugin.value ? plugin.value.name : ""
|
||||
"name" in plugin.value && typeof plugin.value.name === "string"
|
||||
? plugin.value.name
|
||||
: ""
|
||||
} ${plugin.description ? `(${plugin.description})` : ""}`
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2557,20 +2557,20 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@koa/router@npm:^15.4.0":
|
||||
version: 15.4.0
|
||||
resolution: "@koa/router@npm:15.4.0"
|
||||
"@koa/router@npm:^15.4.0, @koa/router@npm:^15.7.0":
|
||||
version: 15.7.0
|
||||
resolution: "@koa/router@npm:15.7.0"
|
||||
dependencies:
|
||||
debug: "npm:^4.4.3"
|
||||
http-errors: "npm:^2.0.1"
|
||||
koa-compose: "npm:^4.1.0"
|
||||
path-to-regexp: "npm:^8.3.0"
|
||||
path-to-regexp: "npm:^8.4.2"
|
||||
peerDependencies:
|
||||
koa: ^2.0.0 || ^3.0.0
|
||||
peerDependenciesMeta:
|
||||
koa:
|
||||
optional: false
|
||||
checksum: 10c0/a16e079115a9e228399b5ca264ca999b2e008d86e29e139343b927eb010e889a2cd17f03194796fb41d82df8572ac25ba112d1d3c342c9e27376894412c349d5
|
||||
checksum: 10c0/da1f23f07684f5b39db5536cd6d4b77f7e38930786c2c0c13cf27d84ab90b6c9eea5ecf17f8f4c1b87ccc822a874f64c351b6e9b4c2e6c9324765564fce689cb
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -6830,15 +6830,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@types/koa-router@npm:^7.4.9":
|
||||
version: 7.4.9
|
||||
resolution: "@types/koa-router@npm:7.4.9"
|
||||
dependencies:
|
||||
"@types/koa": "npm:*"
|
||||
checksum: 10c0/296218c302347e5147b8cd5a6f50312a9d9937ad1082f10d97022841a09c9bc2a821cf3ea381d4ca9dff5643e8c03fe2be1af1bdaba8a065579c54abb1a8dfe1
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@types/koa-send@npm:^4.1.6":
|
||||
version: 4.1.6
|
||||
resolution: "@types/koa-send@npm:4.1.6"
|
||||
@@ -7957,7 +7948,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"any-promise@npm:^1.0.0, any-promise@npm:^1.1.0":
|
||||
"any-promise@npm:^1.0.0":
|
||||
version: 1.3.0
|
||||
resolution: "any-promise@npm:1.3.0"
|
||||
checksum: 10c0/60f0298ed34c74fef50daab88e8dab786036ed5a7fad02e012ab57e376e0a0b4b29e83b95ea9b5e7d89df762f5f25119b83e00706ecaccb22cfbacee98d74889
|
||||
@@ -12288,7 +12279,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"http-errors@npm:^1.3.1, http-errors@npm:^1.7.3, http-errors@npm:~1.8.0":
|
||||
"http-errors@npm:^1.7.3, http-errors@npm:~1.8.0":
|
||||
version: 1.8.1
|
||||
resolution: "http-errors@npm:1.8.1"
|
||||
dependencies:
|
||||
@@ -13650,15 +13641,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"koa-compose@npm:^3.0.0":
|
||||
version: 3.2.1
|
||||
resolution: "koa-compose@npm:3.2.1"
|
||||
dependencies:
|
||||
any-promise: "npm:^1.1.0"
|
||||
checksum: 10c0/10f695cf75906d0054d60d29e3a18e8df8962f1a050823bf503711819294283aae92fc145b86ea8e5dd438fc938a501145a8b6447e87cb6374084434eeeeed2f
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"koa-compose@npm:^4.1.0":
|
||||
version: 4.1.0
|
||||
resolution: "koa-compose@npm:4.1.0"
|
||||
@@ -13717,20 +13699,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"koa-router@npm:7.4.0":
|
||||
version: 7.4.0
|
||||
resolution: "koa-router@npm:7.4.0"
|
||||
dependencies:
|
||||
debug: "npm:^3.1.0"
|
||||
http-errors: "npm:^1.3.1"
|
||||
koa-compose: "npm:^3.0.0"
|
||||
methods: "npm:^1.0.1"
|
||||
path-to-regexp: "npm:^1.1.1"
|
||||
urijs: "npm:^1.19.0"
|
||||
checksum: 10c0/1a3ca392668e0a42222523ae459555010a493b759b934164d98b497e1b25ba57d7a8ee463cf351f815b620a4762f7c85ad8593b7d1cb7d1b2c26c15fa919c7f3
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"koa-send@npm:5.0.1, koa-send@npm:^5.0.0, koa-send@npm:^5.0.1":
|
||||
version: 5.0.1
|
||||
resolution: "koa-send@npm:5.0.1"
|
||||
@@ -14528,13 +14496,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"methods@npm:^1.0.1":
|
||||
version: 1.1.2
|
||||
resolution: "methods@npm:1.1.2"
|
||||
checksum: 10c0/bdf7cc72ff0a33e3eede03708c08983c4d7a173f91348b4b1e4f47d4cdbf734433ad971e7d1e8c77247d9e5cd8adb81ea4c67b0a2db526b758b2233d7814b8b2
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"micromatch@npm:^4.0.2":
|
||||
version: 4.0.8
|
||||
resolution: "micromatch@npm:4.0.8"
|
||||
@@ -15486,6 +15447,7 @@ __metadata:
|
||||
"@hocuspocus/provider": "npm:1.1.3"
|
||||
"@hocuspocus/server": "npm:1.1.3"
|
||||
"@juggle/resize-observer": "npm:^3.4.0"
|
||||
"@koa/router": "npm:^15.7.0"
|
||||
"@linear/sdk": "npm:^97.0.0"
|
||||
"@mermaid-js/layout-elk": "npm:0.2.2"
|
||||
"@modelcontextprotocol/sdk": "npm:^1.31.0"
|
||||
@@ -15543,7 +15505,6 @@ __metadata:
|
||||
"@types/koa-compress": "npm:^4.0.7"
|
||||
"@types/koa-logger": "npm:^3.1.5"
|
||||
"@types/koa-mount": "npm:^4.0.5"
|
||||
"@types/koa-router": "npm:^7.4.9"
|
||||
"@types/koa-send": "npm:^4.1.6"
|
||||
"@types/koa-sslify": "npm:^4.0.6"
|
||||
"@types/koa-useragent": "npm:^2.1.2"
|
||||
@@ -15643,7 +15604,6 @@ __metadata:
|
||||
koa-helmet: "npm:^6.1.0"
|
||||
koa-logger: "npm:^3.2.1"
|
||||
koa-mount: "npm:^4.2.0"
|
||||
koa-router: "npm:7.4.0"
|
||||
koa-send: "npm:5.0.1"
|
||||
koa-sslify: "npm:5.0.1"
|
||||
koa-useragent: "npm:^4.1.0"
|
||||
@@ -16414,7 +16374,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"path-to-regexp@npm:^1.1.1, path-to-regexp@npm:^1.7.0":
|
||||
"path-to-regexp@npm:^1.7.0":
|
||||
version: 1.9.0
|
||||
resolution: "path-to-regexp@npm:1.9.0"
|
||||
dependencies:
|
||||
@@ -16430,7 +16390,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"path-to-regexp@npm:^8.0.0, path-to-regexp@npm:^8.3.0":
|
||||
"path-to-regexp@npm:^8.0.0, path-to-regexp@npm:^8.4.2":
|
||||
version: 8.4.2
|
||||
resolution: "path-to-regexp@npm:8.4.2"
|
||||
checksum: 10c0/05b115c49b47ad252ce05faa32930f643f23769c68b8bcfe78ad833545140c48bbffb3266986d6c8d5db13a64cf12e07e0d72d9882cab830efeefa553533ebaf
|
||||
@@ -20449,13 +20409,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"urijs@npm:^1.19.0":
|
||||
version: 1.19.11
|
||||
resolution: "urijs@npm:1.19.11"
|
||||
checksum: 10c0/96e15eea5b41a99361d506e4d8fcc64dc43f334bd5fd34e08261467b6954b97a6b45929a8d6c79e2dc76aadfd6ca950e0f4bd7f3c0757a08978429634d07eda1
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"url-parse@npm:^1.5.3":
|
||||
version: 1.5.10
|
||||
resolution: "url-parse@npm:1.5.10"
|
||||
|
||||
Reference in new issue
Block a user