Skip to content

Commit cf2e9d9

Browse files
committed
重构启动脚本并添加欢迎页面模板
1 parent 6c5032c commit cf2e9d9

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

examples/showcase/project-tracker/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"dist"
2525
],
2626
"scripts": {
27-
"start": "objectql serve --dir src",
27+
"dev": "objectql dev --dir src",
28+
"start": "objectql start --dir src",
2829
"seed": "ts-node src/seed.ts",
2930
"codegen": "objectql types -s src -o src/types",
3031
"build": "npm run codegen && tsc && rsync -a --include '*/' --include '*.yml' --exclude '*' src/ dist/",

packages/runtime/server/src/adapters/node.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { generateOpenAPI } from '../openapi';
66
import { createFileUploadHandler, createBatchFileUploadHandler, createFileDownloadHandler } from '../file-handler';
77
import { LocalFileStorage } from '../storage';
88
import { escapeRegexPath } from '../utils';
9+
import { getWelcomePageHtml } from '../templates';
910

1011
/**
1112
* Options for createNodeHandler
@@ -241,6 +242,13 @@ export function createNodeHandler(app: IObjectQL, options?: NodeHandlerOptions)
241242

242243
// Special case for root: since we accept POST / (RPC), correct response for GET / is 405
243244
if (pathName === '/') {
245+
if (method === 'GET') {
246+
res.setHeader('Content-Type', 'text/html; charset=utf-8');
247+
res.statusCode = 200;
248+
res.end(getWelcomePageHtml(routes));
249+
return;
250+
}
251+
244252
res.setHeader('Allow', 'POST');
245253
res.statusCode = 405;
246254
res.end(JSON.stringify({ error: { code: ErrorCode.INVALID_REQUEST, message: 'Method Not Allowed. Use POST for JSON-RPC.' } }));
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
export function getWelcomePageHtml(routes: { rpc: string; data: string; }) {
2+
return `<!DOCTYPE html>
3+
<html>
4+
<head>
5+
<title>ObjectQL Server</title>
6+
<style>
7+
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; max-width: 800px; margin: 40px auto; padding: 20px; line-height: 1.6; color: #333; }
8+
h1 { margin-bottom: 10px; }
9+
code { background: #f4f4f4; padding: 2px 5px; border-radius: 3px; font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace; }
10+
.card { border: 1px solid #e1e4e8; border-radius: 6px; padding: 24px; margin-top: 24px; box-shadow: 0 1px 3px rgba(0,0,0,0.04); }
11+
.status { color: #28a745; font-weight: 600; display: inline-flex; align-items: center; }
12+
.status::before { content: ""; display: inline-block; width: 10px; height: 10px; background: #28a745; border-radius: 50%; margin-right: 8px; }
13+
a { color: #0366d6; text-decoration: none; }
14+
a:hover { text-decoration: underline; }
15+
ul { list-style-type: none; padding: 0; }
16+
li { padding: 8px 0; border-bottom: 1px solid #f1f1f1; }
17+
li:last-child { border-bottom: none; }
18+
</style>
19+
</head>
20+
<body>
21+
<div style="margin-bottom: 20px;">
22+
<span class="status">Running</span>
23+
</div>
24+
<h1>ObjectQL Server</h1>
25+
<p>The server is operational and ready to accept requests.</p>
26+
27+
<div class="card">
28+
<h3 style="margin-top: 0">API Endpoints</h3>
29+
<ul>
30+
<li><strong>JSON-RPC:</strong> <code>POST ${routes.rpc}</code></li>
31+
<li><strong>REST API:</strong> <code>GET ${routes.data}/:object</code></li>
32+
<li><strong>OpenAPI Spec:</strong> <a href="/openapi.json">/openapi.json</a></li>
33+
</ul>
34+
</div>
35+
36+
<div class="card">
37+
<h3 style="margin-top: 0">Useful Links</h3>
38+
<ul>
39+
<li><a href="https://objectql.org/docs" target="_blank">Documentation</a></li>
40+
<li><a href="https://github.com/objectql/objectql" target="_blank">GitHub Repository</a></li>
41+
</ul>
42+
</div>
43+
44+
<p style="margin-top: 40px; color: #666; font-size: 0.85em; text-align: center;">
45+
Powered by <strong>ObjectQL</strong>
46+
</p>
47+
</body>
48+
</html>`;
49+
}

0 commit comments

Comments
 (0)