From 8b0a540eb13084df97c3941c4d7630ee790b1cf5 Mon Sep 17 00:00:00 2001 From: Yufan Sheng Date: Mon, 17 Jun 2024 22:36:04 +0800 Subject: [PATCH] feat: bump the astro to latest version for fixing the container loading issues. --- .env.example | 3 ++ package-lock.json | 64 ++++++++++++++++---------------- package.json | 6 +-- src/components/comment/artalk.ts | 4 +- src/helpers/container.ts | 25 ++----------- src/helpers/db/pool.ts | 18 ++++++--- 6 files changed, 55 insertions(+), 65 deletions(-) diff --git a/.env.example b/.env.example index e9667ee..b2446e9 100644 --- a/.env.example +++ b/.env.example @@ -12,3 +12,6 @@ POSTGRES_PORT= POSTGRES_USERNAME= POSTGRES_PASSWORD= POSTGRES_DATABASE= + +# Artalk configuration +ARTALK_HOST= diff --git a/package-lock.json b/package-lock.json index d47d21a..0d047e5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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" diff --git a/package.json b/package.json index 93898ff..0ad3328 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/components/comment/artalk.ts b/src/components/comment/artalk.ts index dc6b1d4..1d0e560 100644 --- a/src/components/comment/artalk.ts +++ b/src/components/comment/artalk.ts @@ -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 => { const data = await fetch(urlJoin(server, '/api/v2/conf')) diff --git a/src/helpers/container.ts b/src/helpers/container.ts index 4016dbf..61666d3 100644 --- a/src/helpers/container.ts +++ b/src/helpers/container.ts @@ -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 ( diff --git a/src/helpers/db/pool.ts b/src/helpers/db/pool.ts index 45c6a59..f0ff192 100644 --- a/src/helpers/db/pool.ts +++ b/src/helpers/db/pool.ts @@ -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, });