Permanently redirect to /s/... for share links (#4067)
This commit is contained in:
@@ -92,7 +92,7 @@ class Share extends IdModel {
|
||||
}
|
||||
|
||||
get canonicalUrl() {
|
||||
return `${this.team.url}/share/${this.id}`;
|
||||
return `${this.team.url}/s/${this.id}`;
|
||||
}
|
||||
|
||||
// associations
|
||||
|
||||
@@ -8,7 +8,7 @@ export default function present(share: Share, isAdmin = false) {
|
||||
documentTitle: share.document?.title,
|
||||
documentUrl: share.document?.url,
|
||||
published: share.published,
|
||||
url: `${share.team.url}/share/${share.id}`,
|
||||
url: share.canonicalUrl,
|
||||
createdBy: presentUser(share.user),
|
||||
includeChildDocuments: share.includeChildDocuments,
|
||||
lastAccessedAt: share.lastAccessedAt || undefined,
|
||||
|
||||
@@ -8,19 +8,19 @@ afterAll(server.disconnect);
|
||||
|
||||
beforeEach(db.flush);
|
||||
|
||||
describe("/share/:id", () => {
|
||||
describe("/s/:id", () => {
|
||||
it("should return standard title in html when loading unpublished share", async () => {
|
||||
const share = await buildShare({
|
||||
published: false,
|
||||
});
|
||||
const res = await server.get(`/share/${share.id}`);
|
||||
const res = await server.get(`/s/${share.id}`);
|
||||
const body = await res.text();
|
||||
expect(res.status).toEqual(404);
|
||||
expect(body).toContain("<title>Outline</title>");
|
||||
});
|
||||
|
||||
it("should return standard title in html when share does not exist", async () => {
|
||||
const res = await server.get(`/share/junk`);
|
||||
const res = await server.get(`/s/junk`);
|
||||
const body = await res.text();
|
||||
expect(res.status).toEqual(404);
|
||||
expect(body).toContain("<title>Outline</title>");
|
||||
@@ -33,7 +33,7 @@ describe("/share/:id", () => {
|
||||
teamId: document.teamId,
|
||||
});
|
||||
await document.destroy();
|
||||
const res = await server.get(`/share/${share.id}`);
|
||||
const res = await server.get(`/s/${share.id}`);
|
||||
const body = await res.text();
|
||||
expect(res.status).toEqual(404);
|
||||
expect(body).toContain("<title>Outline</title>");
|
||||
@@ -45,7 +45,7 @@ describe("/share/:id", () => {
|
||||
documentId: document.id,
|
||||
teamId: document.teamId,
|
||||
});
|
||||
const res = await server.get(`/share/${share.id}`);
|
||||
const res = await server.get(`/s/${share.id}`);
|
||||
const body = await res.text();
|
||||
expect(res.status).toEqual(200);
|
||||
expect(body).toContain(`<title>${document.title}</title>`);
|
||||
@@ -57,7 +57,7 @@ describe("/share/:id", () => {
|
||||
documentId: document.id,
|
||||
teamId: document.teamId,
|
||||
});
|
||||
const res = await server.get(`/share/${share.id}/doc/${document.urlId}`);
|
||||
const res = await server.get(`/s/${share.id}/doc/${document.urlId}`);
|
||||
const body = await res.text();
|
||||
expect(res.status).toEqual(200);
|
||||
expect(body).toContain(`<title>${document.title}</title>`);
|
||||
|
||||
@@ -25,6 +25,14 @@ koa.use(
|
||||
|
||||
koa.use<BaseContext, UserAgentContext>(userAgent);
|
||||
|
||||
router.use(
|
||||
["/share/:shareId", "/share/:shareId/doc/:documentSlug", "/share/:shareId/*"],
|
||||
(ctx) => {
|
||||
ctx.redirect(ctx.path.replace(/^\/share/, "/s"));
|
||||
ctx.status = 301;
|
||||
}
|
||||
);
|
||||
|
||||
if (isProduction) {
|
||||
router.get("/static/*", async (ctx) => {
|
||||
try {
|
||||
@@ -84,9 +92,9 @@ router.get("/opensearch.xml", (ctx) => {
|
||||
ctx.body = opensearchResponse(ctx.request.URL.origin);
|
||||
});
|
||||
|
||||
router.get("/share/:shareId", renderShare);
|
||||
router.get("/share/:shareId/doc/:documentSlug", renderShare);
|
||||
router.get("/share/:shareId/*", renderShare);
|
||||
router.get("/s/:shareId", renderShare);
|
||||
router.get("/s/:shareId/doc/:documentSlug", renderShare);
|
||||
router.get("/s/:shareId/*", renderShare);
|
||||
|
||||
// catch all for application
|
||||
router.get("*", renderApp);
|
||||
|
||||
Reference in New Issue
Block a user