@horizonwing/engine 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -1
- package/src/account-pages.tsx +1 -0
- package/src/auth.tsx +4 -3
- package/src/platform.node.ts +23 -0
- package/src/sections/blog/index.tsx +1 -0
- package/src/sections/blog/views/pages.tsx +1 -0
- package/src/sections/docs/index.tsx +1 -0
- package/src/sections/docs/views/pages.tsx +1 -0
- package/src/sections/landing/index.tsx +1 -0
- package/src/sections/landing/views/pages.tsx +1 -0
- package/src/views/error.tsx +1 -0
- package/src/views/index.tsx +1 -0
- package/src/views/layout.tsx +1 -0
- package/tsconfig.json +32 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@horizonwing/engine",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "kit 建站引擎核心:Hono 双入口组装、SWR 渲染缓存、内容引擎、Section 协议、SEO/feeds、auth",
|
|
6
6
|
"type": "module",
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"src",
|
|
48
48
|
"drizzle",
|
|
49
49
|
"themes",
|
|
50
|
+
"tsconfig.json",
|
|
50
51
|
"README.md"
|
|
51
52
|
],
|
|
52
53
|
"scripts": {
|
package/src/account-pages.tsx
CHANGED
package/src/auth.tsx
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** @jsxImportSource hono/jsx */
|
|
1
2
|
import { Hono } from 'hono';
|
|
2
3
|
import type { Context } from 'hono';
|
|
3
4
|
import { betterAuth } from 'better-auth';
|
|
@@ -36,7 +37,7 @@ export interface AuthStack {
|
|
|
36
37
|
* 来源集合(M4 技术债清偿 R3:端口硬编码改读 env):
|
|
37
38
|
* - 始终含 baseURL;
|
|
38
39
|
* - KIT_TRUSTED_ORIGINS(逗号分隔)配置后完全以它为准(追加语义);
|
|
39
|
-
* -
|
|
40
|
+
* - 未配置时用本地 dev 默认三端口(3000/3001,随默认端口 3000 改版同步)。
|
|
40
41
|
*/
|
|
41
42
|
function collectTrustedOrigins(baseURL: string, env: PlatformEnv): string[] {
|
|
42
43
|
const origins = new Set<string>([baseURL]);
|
|
@@ -51,7 +52,7 @@ function collectTrustedOrigins(baseURL: string, env: PlatformEnv): string[] {
|
|
|
51
52
|
const defaults =
|
|
52
53
|
fromEnv.length > 0
|
|
53
54
|
? fromEnv
|
|
54
|
-
: ['http://localhost:
|
|
55
|
+
: ['http://localhost:3000', 'http://localhost:3001', 'http://127.0.0.1:3000'];
|
|
55
56
|
for (const o of defaults) origins.add(o);
|
|
56
57
|
return [...origins];
|
|
57
58
|
}
|
|
@@ -114,7 +115,7 @@ function resolveBaseURL(config: EngineConfig): string {
|
|
|
114
115
|
if (config.auth?.baseURL) return config.auth.baseURL.replace(/\/+$/, '');
|
|
115
116
|
const siteUrl = config.site.url?.replace(/\/+$/, '');
|
|
116
117
|
if (siteUrl) return siteUrl;
|
|
117
|
-
return 'http://localhost:
|
|
118
|
+
return 'http://localhost:3000';
|
|
118
119
|
}
|
|
119
120
|
|
|
120
121
|
export function createAuthStack(config: EngineConfig): AuthStack {
|
package/src/platform.node.ts
CHANGED
|
@@ -42,6 +42,29 @@ export interface NodePlatformOptions {
|
|
|
42
42
|
* 与 D1 在「全 await」纪律下查询面同形,这里按 engine/db.ts 的统一 async 形态收窄,
|
|
43
43
|
* service 层单实现覆盖双平台。
|
|
44
44
|
*/
|
|
45
|
+
/**
|
|
46
|
+
* 端口占用探测:优先用 preferred,被占用则向后找(+1..+10)。
|
|
47
|
+
* 零依赖 node:net 试绑——绑定成功立刻关闭(SO_REUSEADDR 语义由 node 默认处理)。
|
|
48
|
+
* 用途:node 入口默认 3000,dev 起服务撞端口时自动让位而不是崩(对齐 Vite/Next 体验)。
|
|
49
|
+
*/
|
|
50
|
+
export async function resolveAvailablePort(
|
|
51
|
+
preferred: number,
|
|
52
|
+
{ host = '0.0.0.0', tries = 10 }: { host?: string; tries?: number } = {},
|
|
53
|
+
): Promise<{ port: number; fellBack: boolean }> {
|
|
54
|
+
const net = await import('node:net');
|
|
55
|
+
const tryBind = (port: number): Promise<boolean> =>
|
|
56
|
+
new Promise((resolve) => {
|
|
57
|
+
const srv = net.createServer();
|
|
58
|
+
srv.once('error', () => resolve(false));
|
|
59
|
+
srv.listen({ port, host }, () => srv.close(() => resolve(true)));
|
|
60
|
+
});
|
|
61
|
+
for (let i = 0; i <= tries; i++) {
|
|
62
|
+
const port = preferred + i;
|
|
63
|
+
if (await tryBind(port)) return { port, fellBack: i > 0 };
|
|
64
|
+
}
|
|
65
|
+
return { port: preferred, fellBack: false };
|
|
66
|
+
}
|
|
67
|
+
|
|
45
68
|
export function createNodePlatform(options: NodePlatformOptions): Platform {
|
|
46
69
|
// ':memory:' 等特殊路径跳过;文件路径确保父目录存在
|
|
47
70
|
if (options.dbPath !== ':memory:' && !options.dbPath.startsWith('file:')) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** @jsxImportSource hono/jsx */
|
|
1
2
|
import type { EngineConfig, ContentArticle, ContentListItem, PagedList } from '../../../types';
|
|
2
3
|
import { buildHead, articleJsonLd, breadcrumbJsonLd, collectionPageJsonLd, personJsonLd } from '../../../seo';
|
|
3
4
|
import { tr, localePrefix, hreflangAlternates, siteLocales, baseLocaleOf, localeSwitchProps } from '../../../i18n';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** @jsxImportSource hono/jsx */
|
|
1
2
|
import type { EngineConfig, ContentArticle, ContentItemWithMeta } from '../../../types';
|
|
2
3
|
import { buildHead, collectionPageJsonLd, breadcrumbJsonLd, articleJsonLd } from '../../../seo';
|
|
3
4
|
import { tr, localePrefix, hreflangAlternates, siteLocales, baseLocaleOf, localeSwitchProps } from '../../../i18n';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** @jsxImportSource hono/jsx */
|
|
1
2
|
import { buildHead, organizationJsonLd, websiteWithSearchJsonLd } from '../../../seo';
|
|
2
3
|
import { tr, localePath, hreflangAlternates, siteLocales, baseLocaleOf, localeSwitchProps } from '../../../i18n';
|
|
3
4
|
import type { EngineConfig } from '../../../types';
|
package/src/views/error.tsx
CHANGED
package/src/views/index.tsx
CHANGED
package/src/views/layout.tsx
CHANGED
package/tsconfig.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
7
|
+
"types": ["node"],
|
|
8
|
+
"jsx": "react-jsx",
|
|
9
|
+
"jsxImportSource": "hono/jsx",
|
|
10
|
+
"strict": true,
|
|
11
|
+
"noUncheckedIndexedAccess": true,
|
|
12
|
+
"noFallthroughCasesInSwitch": true,
|
|
13
|
+
"allowImportingTsExtensions": true,
|
|
14
|
+
"forceConsistentCasingInFileNames": true,
|
|
15
|
+
"skipLibCheck": true,
|
|
16
|
+
"esModuleInterop": true,
|
|
17
|
+
"resolveJsonModule": true,
|
|
18
|
+
"isolatedModules": true,
|
|
19
|
+
"verbatimModuleSyntax": true,
|
|
20
|
+
"noEmit": true,
|
|
21
|
+
"allowJs": true,
|
|
22
|
+
"checkJs": false
|
|
23
|
+
},
|
|
24
|
+
"include": [
|
|
25
|
+
"src/**/*.ts",
|
|
26
|
+
"src/**/*.tsx",
|
|
27
|
+
"drizzle/**/*.ts",
|
|
28
|
+
"test/**/*.ts",
|
|
29
|
+
"vitest.config.ts"
|
|
30
|
+
],
|
|
31
|
+
"exclude": ["node_modules", "dist"]
|
|
32
|
+
}
|