Compare commits
1 commit
main
...
fix-cache-
Author | SHA1 | Date | |
---|---|---|---|
![]() |
b86dce69e9 |
8 changed files with 22 additions and 41 deletions
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "lemmy-ui",
|
"name": "lemmy-ui",
|
||||||
"version": "0.18.1-rc.5",
|
"version": "0.18.1-rc.4",
|
||||||
"description": "An isomorphic UI for lemmy",
|
"description": "An isomorphic UI for lemmy",
|
||||||
"repository": "https://github.com/LemmyNet/lemmy-ui",
|
"repository": "https://github.com/LemmyNet/lemmy-ui",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
|
|
|
@ -5,13 +5,9 @@ export default async ({ res }: { res: Response }) => {
|
||||||
|
|
||||||
res.send(
|
res.send(
|
||||||
`Contact: mailto:security@lemmy.ml
|
`Contact: mailto:security@lemmy.ml
|
||||||
Contact: mailto:admin@` +
|
Contact: mailto:admin@${process.env.LEMMY_UI_LEMMY_EXTERNAL_HOST}
|
||||||
process.env.LEMMY_UI_LEMMY_EXTERNAL_HOST +
|
Contact: mailto:security@${process.env.LEMMY_UI_LEMMY_EXTERNAL_HOST}
|
||||||
`
|
Expires: 2024-01-01T04:59:00.000Z
|
||||||
Contact: mailto:security@` +
|
|
||||||
process.env.LEMMY_UI_LEMMY_EXTERNAL_HOST +
|
|
||||||
`
|
|
||||||
Expires: 2024-01-01T04:59:00.000Z
|
|
||||||
`
|
`
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -20,13 +20,7 @@ const [hostname, port] = process.env["LEMMY_UI_HOST"]
|
||||||
|
|
||||||
server.use(express.json());
|
server.use(express.json());
|
||||||
server.use(express.urlencoded({ extended: false }));
|
server.use(express.urlencoded({ extended: false }));
|
||||||
server.use(
|
server.use(getStaticDir(), express.static(path.resolve("./dist")));
|
||||||
getStaticDir(),
|
|
||||||
express.static(path.resolve("./dist"), {
|
|
||||||
maxAge: 24 * 60 * 60 * 1000, // 1 day
|
|
||||||
immutable: true,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
server.use(setCacheControl);
|
server.use(setCacheControl);
|
||||||
|
|
||||||
if (!process.env["LEMMY_UI_DISABLE_CSP"] && !process.env["LEMMY_UI_DEBUG"]) {
|
if (!process.env["LEMMY_UI_DISABLE_CSP"] && !process.env["LEMMY_UI_DEBUG"]) {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import type { NextFunction, Request, Response } from "express";
|
import type { NextFunction, Response } from "express";
|
||||||
import { UserService } from "../shared/services";
|
import { UserService } from "../shared/services";
|
||||||
|
|
||||||
export function setDefaultCsp({
|
export function setDefaultCsp({
|
||||||
|
@ -22,27 +22,20 @@ export function setDefaultCsp({
|
||||||
// interval is rather arbitrary and could be set higher (less server load) or lower (fresher data).
|
// interval is rather arbitrary and could be set higher (less server load) or lower (fresher data).
|
||||||
//
|
//
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
|
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
|
||||||
export function setCacheControl(
|
export function setCacheControl({
|
||||||
req: Request,
|
res,
|
||||||
res: Response,
|
next,
|
||||||
next: NextFunction
|
}: {
|
||||||
) {
|
res: Response;
|
||||||
|
next: NextFunction;
|
||||||
|
}) {
|
||||||
const user = UserService.Instance;
|
const user = UserService.Instance;
|
||||||
let caching: string;
|
let caching: string;
|
||||||
|
|
||||||
if (
|
if (user.auth()) {
|
||||||
process.env.NODE_ENV === "production" &&
|
caching = "private";
|
||||||
(req.path.match(/\.(js|css|txt|manifest\.webmanifest)\/?$/) ||
|
|
||||||
req.path.includes("/css/themelist"))
|
|
||||||
) {
|
|
||||||
// Static content gets cached publicly for a day
|
|
||||||
caching = "public, max-age=86400";
|
|
||||||
} else {
|
} else {
|
||||||
if (user.auth()) {
|
caching = "public, max-age=5";
|
||||||
caching = "private";
|
|
||||||
} else {
|
|
||||||
caching = "public, max-age=5";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
res.setHeader("Cache-Control", caching);
|
res.setHeader("Cache-Control", caching);
|
||||||
|
|
|
@ -24,7 +24,7 @@ export async function createSsrHtml(
|
||||||
|
|
||||||
if (!appleTouchIcon) {
|
if (!appleTouchIcon) {
|
||||||
appleTouchIcon = site?.site_view.site.icon
|
appleTouchIcon = site?.site_view.site.icon
|
||||||
? `data:image/png;base64,${await sharp(
|
? `data:image/png;base64,${sharp(
|
||||||
await fetchIconPng(site.site_view.site.icon)
|
await fetchIconPng(site.site_view.site.icon)
|
||||||
)
|
)
|
||||||
.resize(180, 180)
|
.resize(180, 180)
|
||||||
|
|
|
@ -403,9 +403,8 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
|
||||||
|
|
||||||
createdLine() {
|
createdLine() {
|
||||||
const post_view = this.postView;
|
const post_view = this.postView;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="small mb-1 mb-md-0">
|
<div className="small">
|
||||||
<span className="me-1">
|
<span className="me-1">
|
||||||
<PersonListing person={post_view.creator} />
|
<PersonListing person={post_view.creator} />
|
||||||
</span>
|
</span>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
export default function isAuthPath(pathname: string) {
|
export default function isAuthPath(pathname: string) {
|
||||||
return /^\/create_.*|inbox|settings|admin|reports|registration_applications/g.test(
|
return /create_.*|inbox|settings|admin|reports|registration_applications/g.test(
|
||||||
pathname
|
pathname
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ const banner = `
|
||||||
@license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL v3.0
|
@license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL v3.0
|
||||||
`;
|
`;
|
||||||
|
|
||||||
function getBase(env, mode) {
|
function getBase(env) {
|
||||||
return {
|
return {
|
||||||
output: {
|
output: {
|
||||||
filename: "js/server.js",
|
filename: "js/server.js",
|
||||||
|
@ -54,7 +54,6 @@ function getBase(env, mode) {
|
||||||
plugins: [
|
plugins: [
|
||||||
new webpack.DefinePlugin({
|
new webpack.DefinePlugin({
|
||||||
"process.env.COMMIT_HASH": `"${env.COMMIT_HASH}"`,
|
"process.env.COMMIT_HASH": `"${env.COMMIT_HASH}"`,
|
||||||
"process.env.NODE_ENV": `"${mode}"`,
|
|
||||||
}),
|
}),
|
||||||
new MiniCssExtractPlugin({
|
new MiniCssExtractPlugin({
|
||||||
filename: "styles/styles.css",
|
filename: "styles/styles.css",
|
||||||
|
@ -70,7 +69,7 @@ function getBase(env, mode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const createServerConfig = (env, mode) => {
|
const createServerConfig = (env, mode) => {
|
||||||
const base = getBase(env, mode);
|
const base = getBase(env);
|
||||||
const config = merge({}, base, {
|
const config = merge({}, base, {
|
||||||
mode,
|
mode,
|
||||||
entry: "./src/server/index.tsx",
|
entry: "./src/server/index.tsx",
|
||||||
|
@ -98,7 +97,7 @@ const createServerConfig = (env, mode) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const createClientConfig = (env, mode) => {
|
const createClientConfig = (env, mode) => {
|
||||||
const base = getBase(env, mode);
|
const base = getBase(env);
|
||||||
const config = merge({}, base, {
|
const config = merge({}, base, {
|
||||||
mode,
|
mode,
|
||||||
entry: "./src/client/index.tsx",
|
entry: "./src/client/index.tsx",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue