Compare commits

..

15 commits
main ... cache

Author SHA1 Message Date
Alec Armbruster
126fcf3d12
Merge branch 'main' into cache 2023-06-29 10:09:32 -04:00
Alec Armbruster
ce5743f17c
implement getStaticDir util 2023-06-29 10:08:12 -04:00
SleeplessOne1917
934b202114 Merge branch 'cache' of https://github.com/LemmyNet/lemmy-ui into cache 2023-06-29 09:39:56 -04:00
SleeplessOne1917
25f65ba6c8 Remove debugging log 2023-06-29 09:39:38 -04:00
SleeplessOne1917
7635fc8ff8
Merge branch 'main' into cache 2023-06-29 09:35:54 -04:00
SleeplessOne1917
c24417b9e9
Update .prettierignore
Co-authored-by: Alec Armbruster <35377827+alectrocute@users.noreply.github.com>
2023-06-29 09:35:23 -04:00
SleeplessOne1917
49c52985c3 Merge branch 'cache' of https://github.com/LemmyNet/lemmy-ui into cache 2023-06-29 09:34:52 -04:00
SleeplessOne1917
6d74f86bd0 Add trailing slash 2023-06-29 09:34:38 -04:00
SleeplessOne1917
abdfb9f3ee
Merge branch 'main' into cache 2023-06-29 09:31:23 -04:00
SleeplessOne1917
fe16b924cb Merge branch 'cache' of https://github.com/LemmyNet/lemmy-ui into cache 2023-06-29 09:30:14 -04:00
SleeplessOne1917
753953ad3e Make hash docker agnostic 2023-06-29 09:25:08 -04:00
Dessalines
3caf913614
Merge branch 'main' into cache 2023-06-29 07:52:16 -04:00
SleeplessOne1917
159f0a3ba6
Merge branch 'main' into cache 2023-06-29 06:19:57 -04:00
SleeplessOne1917
c7ea1b7c56 Address PR feedback 2023-06-29 06:18:31 -04:00
SleeplessOne1917
aaf9bc970c Use git hash to break cache 2023-06-28 22:22:06 -04:00
10 changed files with 27 additions and 53 deletions

View file

@ -27,7 +27,7 @@ COPY .git .git
RUN echo "export const VERSION = '$(git describe --tag)';" > "src/shared/version.ts"
RUN yarn --production --prefer-offline
RUN NODE_OPTIONS="--max-old-space-size=8192" yarn build:prod
RUN yarn build:prod
# Prune the image
RUN node-prune /usr/src/app/node_modules

View file

@ -1,6 +1,6 @@
{
"name": "lemmy-ui",
"version": "0.18.1-rc.5",
"version": "0.18.1-rc.3",
"description": "An isomorphic UI for lemmy",
"repository": "https://github.com/LemmyNet/lemmy-ui",
"license": "AGPL-3.0",
@ -22,16 +22,9 @@
"translations:update": "git submodule update --remote --recursive"
},
"lint-staged": {
"*.{ts,tsx,js}": [
"prettier --write",
"eslint --fix"
],
"*.{css, scss}": [
"prettier --write"
],
"package.json": [
"sortpack"
]
"*.{ts,tsx,js}": ["prettier --write", "eslint --fix"],
"*.{css, scss}": ["prettier --write"],
"package.json": ["sortpack"]
},
"dependencies": {
"@babel/plugin-proposal-decorators": "^7.21.0",

View file

@ -20,13 +20,7 @@ const [hostname, port] = process.env["LEMMY_UI_HOST"]
server.use(express.json());
server.use(express.urlencoded({ extended: false }));
server.use(
getStaticDir(),
express.static(path.resolve("./dist"), {
maxAge: 24 * 60 * 60 * 1000, // 1 day
immutable: true,
})
);
server.use(getStaticDir(), express.static(path.resolve("./dist")));
server.use(setCacheControl);
if (!process.env["LEMMY_UI_DISABLE_CSP"] && !process.env["LEMMY_UI_DEBUG"]) {

View file

@ -1,4 +1,4 @@
import type { NextFunction, Request, Response } from "express";
import type { NextFunction, Response } from "express";
import { UserService } from "../shared/services";
export function setDefaultCsp({
@ -18,33 +18,24 @@ export function setDefaultCsp({
// Set cache-control headers. If user is logged in, set `private` to prevent storing data in
// shared caches (eg nginx) and leaking of private data. If user is not logged in, allow caching
// all responses for 5 seconds to reduce load on backend and database. The specific cache
// all responses for 60 seconds to reduce load on backend and database. The specific cache
// 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
export function setCacheControl(
req: Request,
res: Response,
next: NextFunction
) {
export function setCacheControl({
res,
next,
}: {
res: Response;
next: NextFunction;
}) {
const user = UserService.Instance;
let caching: string;
if (
process.env.NODE_ENV === "production" &&
(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";
if (user.auth()) {
caching = "private";
} else {
if (user.auth()) {
caching = "private";
} else {
caching = "public, max-age=5";
}
caching = "public, max-age=60";
}
res.setHeader("Cache-Control", caching);
next();

View file

@ -24,7 +24,7 @@ export async function createSsrHtml(
if (!appleTouchIcon) {
appleTouchIcon = site?.site_view.site.icon
? `data:image/png;base64,${await sharp(
? `data:image/png;base64,${sharp(
await fetchIconPng(site.site_view.site.icon)
)
.resize(180, 180)

View file

@ -279,15 +279,13 @@ export class Home extends Component<any, HomeState> {
trendingCommunitiesRes,
commentsRes,
postsRes,
tagline: getRandomFromList(this.state?.siteRes?.taglines ?? [])
?.content,
isIsomorphic: true,
};
HomeCacheService.postsRes = postsRes;
}
this.state.tagline = getRandomFromList(
this.state?.siteRes?.taglines ?? []
)?.content;
}
componentWillUnmount() {

View file

@ -141,7 +141,7 @@ export class TaglineForm extends Component<TaglineFormProps, TaglineFormState> {
handleEditTaglineClick(d: { i: TaglineForm; index: number }, event: any) {
event.preventDefault();
if (d.i.state.editingRow == d.index) {
if (this.state.editingRow == d.index) {
d.i.setState({ editingRow: undefined });
} else {
d.i.setState({ editingRow: d.index });

View file

@ -403,9 +403,8 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
createdLine() {
const post_view = this.postView;
return (
<div className="small mb-1 mb-md-0">
<div className="small">
<span className="me-1">
<PersonListing person={post_view.creator} />
</span>

View file

@ -1,5 +1,5 @@
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
);
}

View file

@ -14,7 +14,7 @@ const banner = `
@license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL v3.0
`;
function getBase(env, mode) {
function getBase(env) {
return {
output: {
filename: "js/server.js",
@ -54,7 +54,6 @@ function getBase(env, mode) {
plugins: [
new webpack.DefinePlugin({
"process.env.COMMIT_HASH": `"${env.COMMIT_HASH}"`,
"process.env.NODE_ENV": `"${mode}"`,
}),
new MiniCssExtractPlugin({
filename: "styles/styles.css",
@ -70,7 +69,7 @@ function getBase(env, mode) {
}
const createServerConfig = (env, mode) => {
const base = getBase(env, mode);
const base = getBase(env);
const config = merge({}, base, {
mode,
entry: "./src/server/index.tsx",
@ -98,7 +97,7 @@ const createServerConfig = (env, mode) => {
};
const createClientConfig = (env, mode) => {
const base = getBase(env, mode);
const base = getBase(env);
const config = merge({}, base, {
mode,
entry: "./src/client/index.tsx",