diff --git a/app/components/PageTitle.tsx b/app/components/PageTitle.tsx index f2c7f777b..076f9fbf7 100644 --- a/app/components/PageTitle.tsx +++ b/app/components/PageTitle.tsx @@ -24,7 +24,7 @@ const PageTitle = ({ title, favicon }: Props) => { )} diff --git a/package.json b/package.json index 91c2bc6b7..49fdd0c15 100644 --- a/package.json +++ b/package.json @@ -125,7 +125,6 @@ "koa-router": "7.4.0", "koa-send": "5.0.1", "koa-sslify": "2.1.2", - "koa-static": "^4.0.1", "koa-useragent": "^4.1.0", "lodash": "^4.17.21", "mammoth": "^1.4.19", @@ -252,8 +251,8 @@ "@types/koa-logger": "^3.1.2", "@types/koa-mount": "^4.0.1", "@types/koa-router": "^7.4.4", + "@types/koa-send": "^4.1.3", "@types/koa-sslify": "^2.1.0", - "@types/koa-static": "^4.0.2", "@types/koa-useragent": "^2.1.2", "@types/markdown-it": "^12.2.3", "@types/markdown-it-container": "^2.0.5", diff --git a/public/Icon-1024.png b/public/images/Icon-1024.png similarity index 100% rename from public/Icon-1024.png rename to public/images/Icon-1024.png diff --git a/public/apple-touch-icon.png b/public/images/apple-touch-icon.png similarity index 100% rename from public/apple-touch-icon.png rename to public/images/apple-touch-icon.png diff --git a/public/favicon-16.png b/public/images/favicon-16.png similarity index 100% rename from public/favicon-16.png rename to public/images/favicon-16.png diff --git a/public/favicon-32.png b/public/images/favicon-32.png similarity index 100% rename from public/favicon-32.png rename to public/images/favicon-32.png diff --git a/public/icon-256.png b/public/images/icon-256.png similarity index 100% rename from public/icon-256.png rename to public/images/icon-256.png diff --git a/public/icon-512.png b/public/images/icon-512.png similarity index 100% rename from public/icon-512.png rename to public/images/icon-512.png diff --git a/server/index.ts b/server/index.ts index 8bd0c0741..3347eb685 100644 --- a/server/index.ts +++ b/server/index.ts @@ -6,7 +6,6 @@ import "./logging/tracing"; // must come before importing any instrumented modul import http from "http"; import https from "https"; import Koa from "koa"; -import compress from "koa-compress"; import helmet from "koa-helmet"; import logger from "koa-logger"; import onerror from "koa-onerror"; @@ -81,7 +80,6 @@ async function start(id: number, disconnect: () => void) { app.use(logger((str) => Logger.info("http", str))); } - app.use(compress()); app.use(helmet()); // catch errors in one place, automatically set status and response headers diff --git a/server/routes/index.ts b/server/routes/index.ts index a066ad5ec..c21d6bf51 100644 --- a/server/routes/index.ts +++ b/server/routes/index.ts @@ -1,8 +1,8 @@ import path from "path"; import Koa, { BaseContext } from "koa"; +import compress from "koa-compress"; import Router from "koa-router"; import send from "koa-send"; -import serve from "koa-static"; import userAgent, { UserAgentContext } from "koa-useragent"; import { languages } from "@shared/i18n"; import env from "@server/env"; @@ -16,16 +16,31 @@ const isProduction = env.ENVIRONMENT === "production"; const koa = new Koa(); const router = new Router(); -// serve public assets -koa.use( - serve(path.resolve(__dirname, "../../../public"), { - // 1 month expiry, these assets are mostly static but do not contain a hash - maxAge: 30 * 24 * 60 * 60 * 1000, - }) -); - koa.use(userAgent); +// serve public assets +router.use(["/images/*", "/email/*"], 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: 7 * 24 * 60 * 60 * 1000, + }); + } catch (err) { + if (err.status !== 404) { + throw err; + } + } + } + + if (!done) { + await next(); + } +}); + router.use( ["/share/:shareId", "/share/:shareId/doc/:documentSlug", "/share/:shareId/*"], (ctx) => { @@ -66,6 +81,8 @@ if (isProduction) { }); } +router.use(compress()); + router.get("/locales/:lng.json", async (ctx) => { const { lng } = ctx.params; diff --git a/server/static/index.html b/server/static/index.html index 0aff0ced8..52a31e6f1 100644 --- a/server/static/index.html +++ b/server/static/index.html @@ -17,13 +17,13 @@ { Outline Search Outline UTF-8 - ${baseUrl}/favicon.ico + ${baseUrl}/images/favicon-16.png ${baseUrl}/search diff --git a/webpack.config.js b/webpack.config.js index 10f01b1ec..cbdcf84e0 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -69,7 +69,7 @@ module.exports = { display: "standalone", icons: [ { - src: path.resolve("public/icon-512.png"), + src: path.resolve("public/images/icon-512.png"), // For Chrome, you must provide at least a 192x192 pixel icon, and a 512x512 pixel icon. // If only those two icon sizes are provided, Chrome will automatically scale the icons // to fit the device. If you'd prefer to scale your own icons, and adjust them for diff --git a/yarn.lock b/yarn.lock index d688ad23f..d255e5c7d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2952,7 +2952,7 @@ dependencies: "@types/koa" "*" -"@types/koa-send@*": +"@types/koa-send@^4.1.3": version "4.1.3" resolved "https://registry.yarnpkg.com/@types/koa-send/-/koa-send-4.1.3.tgz#17193c6472ae9e5d1b99ae8086949cc4fd69179d" integrity sha512-daaTqPZlgjIJycSTNjKpHYuKhXYP30atFc1pBcy6HHqB9+vcymDgYTguPdx9tO4HMOqNyz6bz/zqpxt5eLR+VA== @@ -2966,14 +2966,6 @@ dependencies: "@types/koa" "*" -"@types/koa-static@^4.0.2": - version "4.0.2" - resolved "https://registry.yarnpkg.com/@types/koa-static/-/koa-static-4.0.2.tgz#a199d2d64d2930755eb3ea370aeaf2cb6f501d67" - integrity sha512-ns/zHg+K6XVPMuohjpOlpkR1WLa4VJ9czgUP9bxkCDn0JZBtUWbD/wKDZzPGDclkQK1bpAEScufCHOy8cbfL0w== - dependencies: - "@types/koa" "*" - "@types/koa-send" "*" - "@types/koa-useragent@^2.1.2": version "2.1.2" resolved "https://registry.yarnpkg.com/@types/koa-useragent/-/koa-useragent-2.1.2.tgz#7c75fe55c742e559c4643d65b34c6ce5945f853f" @@ -6193,7 +6185,7 @@ debug@4, debug@^4.0.1, debug@^4.1.0, debug@^4.1.1, debug@^4.3.1, debug@^4.3.2, d dependencies: ms "2.1.2" -debug@^2.2.0, debug@^2.3.3, debug@^2.6.1, debug@^2.6.3, debug@^2.6.8, debug@^2.6.9: +debug@^2.2.0, debug@^2.3.3, debug@^2.6.1, debug@^2.6.8, debug@^2.6.9: version "2.6.9" resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f" integrity sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA== @@ -8512,7 +8504,7 @@ http-errors@2.0.0: statuses "2.0.1" toidentifier "1.0.1" -http-errors@^1.3.1, http-errors@^1.6.1, http-errors@^1.6.3, http-errors@^1.7.3, http-errors@^1.8.0: +http-errors@^1.3.1, http-errors@^1.6.3, http-errors@^1.7.3, http-errors@^1.8.0: version "1.8.1" resolved "https://registry.yarnpkg.com/http-errors/-/http-errors-1.8.1.tgz#7c3f28577cbc8a207388455dbd62295ed07bd68c" integrity sha512-Kpk9Sm7NmI+RHhnj6OIWDI1d6fIoFAtFt9RLaTMRlg/8w49juAStsrBgp0Dp4OdxdVbRIeKhtCUvoi/RuAhO4g== @@ -10150,29 +10142,11 @@ koa-send@5.0.1, koa-send@^5.0.0: http-errors "^1.7.3" resolve-path "^1.4.0" -koa-send@^4.1.3: - version "4.1.3" - resolved "https://registry.yarnpkg.com/koa-send/-/koa-send-4.1.3.tgz#0822207bbf5253a414c8f1765ebc29fa41353cb6" - integrity sha512-3UetMBdaXSiw24qM2Mx5mKmxLKw5ZTPRjACjfhK6Haca55RKm9hr/uHDrkrxhSl5/S1CKI/RivZVIopiatZuTA== - dependencies: - debug "^2.6.3" - http-errors "^1.6.1" - mz "^2.6.0" - resolve-path "^1.4.0" - koa-sslify@2.1.2: version "2.1.2" resolved "https://registry.yarnpkg.com/koa-sslify/-/koa-sslify-2.1.2.tgz#8947fd53949d69d539607814097863c1ecf38f30" integrity sha1-iUf9U5SdadU5YHgUCXhjwezzjzA= -koa-static@^4.0.1: - version "4.0.3" - resolved "https://registry.yarnpkg.com/koa-static/-/koa-static-4.0.3.tgz#5f93ad00fb1905db9ce46667c0e8bb7d22abfcd8" - integrity sha512-JGmxTuPWy4bH7bt6gD/OMWkhprawvRmzJSr8TWKmTL4N7+IMv3s0SedeQi5S4ilxM9Bo6ptkCyXj/7wf+VS5tg== - dependencies: - debug "^3.1.0" - koa-send "^4.1.3" - koa-static@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/koa-static/-/koa-static-5.0.0.tgz#5e92fc96b537ad5219f425319c95b64772776943" @@ -11122,7 +11096,7 @@ msgpackr@^1.5.2: optionalDependencies: msgpackr-extract "^2.0.2" -mz@^2.4.0, mz@^2.6.0: +mz@^2.4.0: version "2.7.0" resolved "https://registry.yarnpkg.com/mz/-/mz-2.7.0.tgz#95008057a56cafadc2bc63dde7f9ff6955948e32" integrity sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q==