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_USERNAME=
POSTGRES_PASSWORD= POSTGRES_PASSWORD=
POSTGRES_DATABASE= POSTGRES_DATABASE=
# Artalk configuration
ARTALK_HOST=

64
package-lock.json generated
View File

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

View File

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

View File

@ -10,7 +10,7 @@ import type {
import { increaseViews } from '@/helpers/db/query'; import { increaseViews } from '@/helpers/db/query';
import { options } from '@/helpers/schema'; import { options } from '@/helpers/schema';
import { urlJoin } from '@/helpers/tools'; import { urlJoin } from '@/helpers/tools';
import { getSecret } from 'astro:env/server'; import { ARTALK_HOST } from 'astro:env/server';
import _ from 'lodash'; import _ from 'lodash';
import { marked } from 'marked'; import { marked } from 'marked';
import * as querystring from 'node:querystring'; import * as querystring from 'node:querystring';
@ -18,7 +18,7 @@ import { ELEMENT_NODE, transform, walk } from 'ultrahtml';
import sanitize from 'ultrahtml/transformers/sanitize'; import sanitize from 'ultrahtml/transformers/sanitize';
// Access the artalk in internal docker host when it was deployed on zeabur. // 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> => { export const getConfig = async (): Promise<CommentConfig | null> => {
const data = await fetch(urlJoin(server, '/api/v2/conf')) 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 { 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'; 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 const container = await AstroContainer.create();
export async function loadRenderers(renderers: AstroRenderer[]) { container.addServerRenderer({ name: 'astro:jsx', renderer: serverRenderer });
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 });
// We only want to make sure the container instance is singleton. // We only want to make sure the container instance is singleton.
export const partialRender = async ( export const partialRender = async (

View File

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