Skip to content

Commit d1c436f

Browse files
committed
本地部署
1 parent 4867f29 commit d1c436f

File tree

10 files changed

+859
-10
lines changed

10 files changed

+859
-10
lines changed

apps/web/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,13 @@ By default, the Cloudflare pages adaptor _does not_ include a `public/_routes.js
4444
In the above example, it's saying _all_ pages should be SSR'd. However, the root static files such as `/favicon.ico` and any static assets in `/build/*` should be excluded from the Functions, and instead treated as a static file.
4545

4646
In most cases the generated `dist/_routes.json` file is ideal. However, if you need more granular control over each path, you can instead provide you're own `public/_routes.json` file. When the project provides its own `public/_routes.json` file, then the Cloudflare adaptor will not auto-generate the routes config and instead use the committed one within the `public` directory.
47+
48+
## Fastify Server
49+
50+
This app has a minimal [Fastify server](https://fastify.dev/) implementation. After running a full build, you can preview the build using the command:
51+
52+
```
53+
pnpm serve
54+
```
55+
56+
Then visit [http://localhost:3000/](http://localhost:3000/)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { nodeServerAdapter } from "@builder.io/qwik-city/adapters/node-server/vite";
2+
import { extendConfig } from "@builder.io/qwik-city/vite";
3+
import baseConfig from "../../vite.config";
4+
5+
export default extendConfig(baseConfig, () => {
6+
return {
7+
build: {
8+
ssr: true,
9+
rollupOptions: {
10+
input: ["src/entry.fastify.tsx", "@qwik-city-plan"],
11+
},
12+
},
13+
plugins: [nodeServerAdapter({ name: "fastify" })],
14+
};
15+
});

apps/web/deploy.nu

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cd ../..
2+
docker build -t gitea.c5y.moe/clansty/maibot-web -f web.Dockerfile --push .
3+

apps/web/package.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,22 @@
55
"type": "module",
66
"scripts": {
77
"build": "qwik build",
8-
"build.server": "vite build -c adapters/cloudflare-pages/vite.config.ts",
98
"build.client": "vite build",
10-
"deploy": "pnpm run build && wrangler pages deploy ./dist",
9+
"build.server": "vite build -c adapters/fastify/vite.config.ts",
10+
"deploy": "nu deploy.nu",
1111
"dev": "vite --mode ssr",
12-
"tail": "wrangler pages deployment tail --project-name maibot-web",
13-
"serve": "wrangler pages dev ./dist --compatibility-flags=nodejs_als"
12+
"serve": "node server/entry.fastify",
13+
"tail": "wrangler pages deployment tail --project-name maibot-web"
1414
},
1515
"dependencies": {
1616
"@clansty/maibot-clients": "workspace:^",
1717
"@clansty/maibot-types": "workspace:^",
18-
"@clansty/maibot-utils": "workspace:^"
18+
"@clansty/maibot-utils": "workspace:^",
19+
"@fastify/compress": "^6.2.1",
20+
"@fastify/static": "^6.10.1",
21+
"dotenv": "^16.3.2",
22+
"fastify": "^4.17.0",
23+
"fastify-plugin": "^4.5.0"
1924
},
2025
"devDependencies": {
2126
"@builder.io/qwik": "^1.7.3",

apps/web/src/entry.fastify.tsx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* WHAT IS THIS FILE?
3+
*
4+
* It's the entry point for the Fastify server when building for production.
5+
*
6+
* Learn more about Node.js server integrations here:
7+
* - https://qwik.dev/docs/deployments/node/
8+
*
9+
*/
10+
import { type PlatformNode } from "@builder.io/qwik-city/middleware/node";
11+
import "dotenv/config";
12+
import Fastify from "fastify";
13+
import { join } from "node:path";
14+
import { fileURLToPath } from "node:url";
15+
import FastifyQwik from "./plugins/fastify-qwik";
16+
17+
declare global {
18+
interface QwikCityPlatform extends PlatformNode {}
19+
}
20+
21+
// Directories where the static assets are located
22+
const distDir = join(fileURLToPath(import.meta.url), "..", "..", "dist");
23+
const buildDir = join(distDir, "build");
24+
25+
// Allow for dynamic port and host
26+
const PORT = parseInt(process.env.PORT ?? "3000");
27+
const HOST = process.env.HOST ?? "0.0.0.0";
28+
29+
const start = async () => {
30+
// Create the fastify server
31+
// https://fastify.dev/docs/latest/Guides/Getting-Started/
32+
const fastify = Fastify({
33+
logger: true,
34+
});
35+
36+
// Enable compression
37+
// https://github.com/fastify/fastify-compress
38+
// IMPORTANT NOTE: THIS MUST BE REGISTERED BEFORE THE fastify-qwik PLUGIN
39+
// await fastify.register(import('@fastify/compress'))
40+
41+
// Handle Qwik City using a plugin
42+
await fastify.register(FastifyQwik, { distDir, buildDir });
43+
44+
// Start the fastify server
45+
await fastify.listen({ port: PORT, host: HOST });
46+
};
47+
48+
start();
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { createQwikCity } from "@builder.io/qwik-city/middleware/node";
2+
import fastifyStatic from "@fastify/static";
3+
import qwikCityPlan from "@qwik-city-plan";
4+
import type { FastifyPluginAsync } from "fastify";
5+
import fastifyPlugin from "fastify-plugin";
6+
7+
import render from "../entry.ssr";
8+
9+
export interface FastifyQwikOptions {
10+
distDir: string;
11+
buildDir: string;
12+
}
13+
14+
const { router, notFound } = createQwikCity({ render, qwikCityPlan });
15+
16+
const qwikPlugin: FastifyPluginAsync<FastifyQwikOptions> = async (
17+
fastify,
18+
options,
19+
) => {
20+
const { buildDir, distDir } = options;
21+
22+
fastify.register(fastifyStatic, {
23+
root: buildDir,
24+
prefix: "/build",
25+
immutable: true,
26+
maxAge: "1y",
27+
decorateReply: false,
28+
});
29+
30+
fastify.register(fastifyStatic, {
31+
root: distDir,
32+
redirect: false,
33+
decorateReply: false,
34+
});
35+
36+
fastify.setNotFoundHandler(async (request, response) => {
37+
await router(request.raw, response.raw, (err) => fastify.log.error(err));
38+
await notFound(request.raw, response.raw, (err) => fastify.log.error(err));
39+
});
40+
};
41+
42+
export default fastifyPlugin(qwikPlugin, { fastify: ">=4.0.0 <6.0.0" });

packages/botcore/src/UserContext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export default class UserContext<T extends BotTypes> {
7474
const currentProfile = await this.getCurrentProfile(false);
7575
const currentProfileId = this.currentProfileId;
7676

77-
let url = `https://maibot-web.pages.dev/${type}/`;
77+
let url = `http://web:3000/${type}/`;
7878
if (currentProfile.dto.type === 'AquaDX-v2') {
7979
url += `aquadx/${encodeURIComponent(currentProfile.dto.username)}`;
8080
} else if (currentProfile.dto.type === 'Minato') {

packages/clients/src/Minato.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ import AquaDxLike from './AquaDxLike';
22

33
export default class Minato extends AquaDxLike {
44
public constructor() {
5-
super('https://minato-web-api.init.ink');
5+
super('http://11.11.41.11');
66
}
7-
}
7+
}

0 commit comments

Comments
 (0)