feat: bump the astro to latest version for fixing the container loading issues.

This commit is contained in:
Yufan Sheng 2024-06-17 22:36:04 +08:00
parent e152e90a5a
commit 8b0a540eb1
Signed by: syhily
GPG Key ID: 9D18A22A7DCD5A9B
6 changed files with 55 additions and 65 deletions

View File

@ -12,3 +12,6 @@ POSTGRES_PORT=
POSTGRES_USERNAME=
POSTGRES_PASSWORD=
POSTGRES_DATABASE=
# Artalk configuration
ARTALK_HOST=

64
package-lock.json generated
View File

@ -9,10 +9,10 @@
"version": "3.0.0",
"license": "MIT",
"dependencies": {
"@astrojs/mdx": "^3.1.0",
"@astrojs/node": "^8.3.0",
"@astrojs/mdx": "^3.1.1",
"@astrojs/node": "^8.3.1",
"@astrojs/rss": "^4.0.6",
"astro": "^4.10.2",
"astro": "^4.10.3",
"drizzle-orm": "^0.31.2",
"fuse.js": "^7.0.0",
"lodash": "^4.17.21",
@ -514,14 +514,14 @@
}
},
"node_modules/@astrojs/mdx": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/@astrojs/mdx/-/mdx-3.1.0.tgz",
"integrity": "sha512-yuGDaOcCAfYgLQvUAlJDezYGK4twHlzW1Kvpyg3inxtDJuAsHdyVyYLWl0Wo5nwkyrbZktdrjnoW5scqzoAqAg==",
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/@astrojs/mdx/-/mdx-3.1.1.tgz",
"integrity": "sha512-Y6Ath3E/DgDsMdbenXai+Qm6DGCMnR6rvgHwK2PUQTs6iKF+oQ8SfZ1zPC1kt22rP1PnA8siYSQhNL91K4eukQ==",
"license": "MIT",
"dependencies": {
"@astrojs/markdown-remark": "5.1.0",
"@mdx-js/mdx": "^3.0.1",
"acorn": "^8.11.3",
"acorn": "^8.12.0",
"es-module-lexer": "^1.5.3",
"estree-util-visit": "^2.0.0",
"github-slugger": "^2.0.0",
@ -543,9 +543,9 @@
}
},
"node_modules/@astrojs/node": {
"version": "8.3.0",
"resolved": "https://registry.npmjs.org/@astrojs/node/-/node-8.3.0.tgz",
"integrity": "sha512-XskynbRTrpY9nqzc4NDrulNWoynRvVO+8UmEKjw6KZABUYUmjZqN88sa/RXtXl0CPI2sPZ5Gzi3WXH8y2PKd5Q==",
"version": "8.3.1",
"resolved": "https://registry.npmjs.org/@astrojs/node/-/node-8.3.1.tgz",
"integrity": "sha512-JwJzE1zyNcb2Tnk1PJIiIV2vGadR/h0C7h3WeN50H7S/DbNpkGrfwKrOxxpZwhkujnudddToA9U4yv+IPlCf0g==",
"license": "MIT",
"dependencies": {
"send": "^0.18.0",
@ -2602,9 +2602,9 @@
]
},
"node_modules/@shikijs/core": {
"version": "1.6.5",
"resolved": "https://registry.npmjs.org/@shikijs/core/-/core-1.6.5.tgz",
"integrity": "sha512-XcQYt6e4L61ruAxHiL3Xg1DL/XkWWjzDdeckB/DtN8jAxoAU+bcxsV6DetC8NafHpL4YpGhxy9iXF0ND/u6HmA==",
"version": "1.7.0",
"resolved": "https://registry.npmjs.org/@shikijs/core/-/core-1.7.0.tgz",
"integrity": "sha512-O6j27b7dGmJbR3mjwh/aHH8Ld+GQvA0OQsNO43wKWnqbAae3AYXrhFyScHGX8hXZD6vX2ngjzDFkZY5srtIJbQ==",
"license": "MIT"
},
"node_modules/@types/acorn": {
@ -3056,9 +3056,9 @@
}
},
"node_modules/astro": {
"version": "4.10.2",
"resolved": "https://registry.npmjs.org/astro/-/astro-4.10.2.tgz",
"integrity": "sha512-SBdkoOanPsxKlKVU4uu/XG0G7NYAFoqmfBtq9SPMJ34B7Hr1MxVdEugERs8IwYN6UaxdDVcqA++9PvH6Onq2cg==",
"version": "4.10.3",
"resolved": "https://registry.npmjs.org/astro/-/astro-4.10.3.tgz",
"integrity": "sha512-TWCJM+Vg+y0UoEz/H75rfp/u2N8yxeQQ2UrU9+fMcbjlzQJtGGDq3ApdundqPZgAuCryRuJnrKytStMZCFnlvQ==",
"license": "MIT",
"dependencies": {
"@astrojs/compiler": "^2.8.0",
@ -3073,7 +3073,7 @@
"@babel/types": "^7.24.7",
"@types/babel__core": "^7.20.5",
"@types/cookie": "^0.6.0",
"acorn": "^8.11.3",
"acorn": "^8.12.0",
"aria-query": "^5.3.0",
"axobject-query": "^4.0.0",
"boxen": "^7.1.1",
@ -3112,13 +3112,13 @@
"rehype": "^13.0.1",
"resolve": "^1.22.8",
"semver": "^7.6.2",
"shiki": "^1.6.3",
"shiki": "^1.6.5",
"string-width": "^7.1.0",
"strip-ansi": "^7.1.0",
"tsconfck": "^3.1.0",
"unist-util-visit": "^5.0.0",
"vfile": "^6.0.1",
"vite": "^5.2.13",
"vite": "^5.3.1",
"vitefu": "^0.2.5",
"which-pm": "^2.2.0",
"yargs-parser": "^21.1.1",
@ -3332,9 +3332,9 @@
}
},
"node_modules/caniuse-lite": {
"version": "1.0.30001634",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001634.tgz",
"integrity": "sha512-fbBYXQ9q3+yp1q1gBk86tOFs4pyn/yxFm5ZNP18OXJDfA3txImOY9PhfxVggZ4vRHDqoU8NrKU81eN0OtzOgRA==",
"version": "1.0.30001636",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001636.tgz",
"integrity": "sha512-bMg2vmr8XBsbL6Lr0UHXy/21m84FTxDLWn2FSqMd5PrlbMxwJlQnC2YWYxVgp66PZE+BBNF2jYQUBKCo1FDeZg==",
"funding": [
{
"type": "opencollective",
@ -4630,9 +4630,9 @@
}
},
"node_modules/hast-util-raw": {
"version": "9.0.3",
"resolved": "https://registry.npmjs.org/hast-util-raw/-/hast-util-raw-9.0.3.tgz",
"integrity": "sha512-ICWvVOF2fq4+7CMmtCPD5CM4QKjPbHpPotE6+8tDooV0ZuyJVUzHsrNX+O5NaRbieTf0F7FfeBOMAwi6Td0+yQ==",
"version": "9.0.4",
"resolved": "https://registry.npmjs.org/hast-util-raw/-/hast-util-raw-9.0.4.tgz",
"integrity": "sha512-LHE65TD2YiNsHD3YuXcKPHXPLuYh/gjp12mOfU8jxSrm1f/yJpsb0F/KKljS6U9LJoP0Ux+tCe8iJ2AsPzTdgA==",
"license": "MIT",
"dependencies": {
"@types/hast": "^3.0.0",
@ -7979,12 +7979,12 @@
}
},
"node_modules/shiki": {
"version": "1.6.5",
"resolved": "https://registry.npmjs.org/shiki/-/shiki-1.6.5.tgz",
"integrity": "sha512-iFzypldJG0zeyRHKAhaSGCf+YWXpMMyUyOrCVFBFKGGdF5vrB6jbd66/SQljxV20aSrVZEAQwUto/hhuNi/CIg==",
"version": "1.7.0",
"resolved": "https://registry.npmjs.org/shiki/-/shiki-1.7.0.tgz",
"integrity": "sha512-H5pMn4JA7ayx8H0qOz1k2qANq6mZVCMl1gKLK6kWIrv1s2Ial4EmD4s4jE8QB5Dw03d/oCQUxc24sotuyR5byA==",
"license": "MIT",
"dependencies": {
"@shikijs/core": "1.6.5"
"@shikijs/core": "1.7.0"
}
},
"node_modules/signal-exit": {
@ -9328,9 +9328,9 @@
}
},
"node_modules/zod-to-json-schema": {
"version": "3.23.0",
"resolved": "https://registry.npmjs.org/zod-to-json-schema/-/zod-to-json-schema-3.23.0.tgz",
"integrity": "sha512-az0uJ243PxsRIa2x1WmNE/pnuA05gUq/JB8Lwe1EDCCL/Fz9MgjYQ0fPlyc2Tcv6aF2ZA7WM5TWaRZVEFaAIag==",
"version": "3.23.1",
"resolved": "https://registry.npmjs.org/zod-to-json-schema/-/zod-to-json-schema-3.23.1.tgz",
"integrity": "sha512-oT9INvydob1XV0v1d2IadrR74rLtDInLvDFfAa1CG0Pmg/vxATk7I2gSelfj271mbzeM4Da0uuDQE/Nkj3DWNw==",
"license": "ISC",
"peerDependencies": {
"zod": "^3.23.3"

View File

@ -41,10 +41,10 @@
]
},
"dependencies": {
"@astrojs/mdx": "^3.1.0",
"@astrojs/node": "^8.3.0",
"@astrojs/mdx": "^3.1.1",
"@astrojs/node": "^8.3.1",
"@astrojs/rss": "^4.0.6",
"astro": "^4.10.2",
"astro": "^4.10.3",
"drizzle-orm": "^0.31.2",
"fuse.js": "^7.0.0",
"lodash": "^4.17.21",

View File

@ -10,7 +10,7 @@ import type {
import { increaseViews } from '@/helpers/db/query';
import { options } from '@/helpers/schema';
import { urlJoin } from '@/helpers/tools';
import { getSecret } from 'astro:env/server';
import { ARTALK_HOST } from 'astro:env/server';
import _ from 'lodash';
import { marked } from 'marked';
import * as querystring from 'node:querystring';
@ -18,7 +18,7 @@ import { ELEMENT_NODE, transform, walk } from 'ultrahtml';
import sanitize from 'ultrahtml/transformers/sanitize';
// Access the artalk in internal docker host when it was deployed on zeabur.
const server = import.meta.env.PROD ? `http://${getSecret('ARTALK_HOST')}:23366` : options.settings.comments.server;
const server = import.meta.env.PROD ? `http://${ARTALK_HOST}:23366` : options.settings.comments.server;
export const getConfig = async (): Promise<CommentConfig | null> => {
const data = await fetch(urlJoin(server, '/api/v2/conf'))

View File

@ -1,28 +1,9 @@
import { getContainerRenderer } from '@astrojs/mdx';
import type { AstroRenderer, SSRLoadedRenderer } from 'astro';
import { experimental_AstroContainer as AstroContainer, type ContainerRenderOptions } from 'astro/container';
import serverRenderer from 'astro/jsx/server.js';
import type { AstroComponentFactory } from 'astro/runtime/server/index.js';
// FIXME: This is a monkey patch which should be removed after bumping the astro to 4.10.3
export async function loadRenderers(renderers: AstroRenderer[]) {
const loadedRenderers = await Promise.all(
renderers.map(async (renderer) => {
const mod = await import(/* @vite-ignore */ renderer.serverEntrypoint);
if (typeof mod.default !== 'undefined') {
return {
...renderer,
ssr: mod.default,
} as SSRLoadedRenderer;
}
return undefined;
}),
);
return loadedRenderers.filter((r): r is SSRLoadedRenderer => Boolean(r));
}
const renderers = await loadRenderers([getContainerRenderer()]);
const container = await AstroContainer.create({ renderers: renderers });
const container = await AstroContainer.create();
container.addServerRenderer({ name: 'astro:jsx', renderer: serverRenderer });
// We only want to make sure the container instance is singleton.
export const partialRender = async (

View File

@ -1,5 +1,11 @@
import * as schema from '@/helpers/db/schema';
import { getSecret } from 'astro:env/server';
import {
POSTGRES_DATABASE,
POSTGRES_HOST,
POSTGRES_PASSWORD,
POSTGRES_PORT,
POSTGRES_USERNAME,
} from 'astro:env/server';
import { drizzle } from 'drizzle-orm/node-postgres';
import pg from 'pg';
@ -13,11 +19,11 @@ const globalForDb = globalThis as unknown as {
const conn =
globalForDb.conn ??
new pg.Pool({
host: getSecret('POSTGRES_HOST'),
port: getSecret('POSTGRES_PORT'),
user: getSecret('POSTGRES_USERNAME'),
password: getSecret('POSTGRES_PASSWORD'),
database: getSecret('POSTGRES_DATABASE'),
host: POSTGRES_HOST,
port: POSTGRES_PORT,
user: POSTGRES_USERNAME,
password: POSTGRES_PASSWORD,
database: POSTGRES_DATABASE,
keepAlive: true,
});