Return cache headers on opensearch.xml response
This commit is contained in:
@@ -8,6 +8,7 @@ import send from "koa-send";
|
||||
import userAgent, { UserAgentContext } from "koa-useragent";
|
||||
import { languages } from "@shared/i18n";
|
||||
import { IntegrationType, TeamPreference } from "@shared/types";
|
||||
import { Day } from "@shared/utils/time";
|
||||
import env from "@server/env";
|
||||
import { NotFoundError } from "@server/errors";
|
||||
import shareDomains from "@server/middlewares/shareDomains";
|
||||
@@ -33,7 +34,7 @@ router.use(["/images/*", "/email/*", "/fonts/*"], async (ctx, next) => {
|
||||
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: 7 * 24 * 60 * 60 * 1000,
|
||||
maxAge: Day * 7,
|
||||
setHeaders: (res) => {
|
||||
res.setHeader("Access-Control-Allow-Origin", "*");
|
||||
},
|
||||
@@ -69,7 +70,7 @@ if (env.isProduction) {
|
||||
await send(ctx, pathname, {
|
||||
root: path.join(__dirname, "../../app/"),
|
||||
// Hashed static assets get 1 year expiry plus immutable flag
|
||||
maxAge: 365 * 24 * 60 * 60 * 1000,
|
||||
maxAge: Day * 365,
|
||||
immutable: true,
|
||||
setHeaders: (res) => {
|
||||
res.setHeader("Service-Worker-Allowed", "/");
|
||||
@@ -103,7 +104,7 @@ router.get("/locales/:lng.json", async (ctx) => {
|
||||
await send(ctx, path.join(lng, "translation.json"), {
|
||||
setHeaders: (res, _, stats) => {
|
||||
res.setHeader("Last-Modified", formatRFC7231(stats.mtime));
|
||||
res.setHeader("Cache-Control", `public, max-age=${7 * 24 * 60 * 60}`);
|
||||
res.setHeader("Cache-Control", `public, max-age=${(7 * Day) / 1000}`);
|
||||
res.setHeader(
|
||||
"ETag",
|
||||
crypto.createHash("md5").update(stats.mtime.toISOString()).digest("hex")
|
||||
@@ -119,7 +120,7 @@ router.get("/robots.txt", (ctx) => {
|
||||
|
||||
router.get("/opensearch.xml", (ctx) => {
|
||||
ctx.type = "text/xml";
|
||||
|
||||
ctx.response.set("Cache-Control", `public, max-age=${(7 * Day) / 1000}`);
|
||||
ctx.body = opensearchResponse(ctx.request.URL.origin);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import env from "@server/env";
|
||||
|
||||
export const opensearchResponse = (baseUrl: string): string => `
|
||||
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/">
|
||||
<ShortName>Outline</ShortName>
|
||||
<Description>Search Outline</Description>
|
||||
<ShortName>${env.APP_NAME}</ShortName>
|
||||
<Description>Search ${env.APP_NAME}</Description>
|
||||
<InputEncoding>UTF-8</InputEncoding>
|
||||
<Image width="16" height="16" type="image/x-icon">${baseUrl}/images/favicon-16.png</Image>
|
||||
<Url type="text/html" method="get" template="${baseUrl}/search/{searchTerms}?ref=opensearch"/>
|
||||
|
||||
Reference in New Issue
Block a user