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