Skip to content

Commit 6a51313

Browse files
committed
refactor(server): update server initialization and plugin structure
1 parent f5bce5c commit 6a51313

4 files changed

Lines changed: 11 additions & 11 deletions

File tree

server/src/_worker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default {
99
request: Request,
1010
env: Env,
1111
): Promise<Response> {
12-
return await server
12+
return await server()
1313
.handle(request)
1414
},
1515
async scheduled(

server/src/base.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import cors from "@elysiajs/cors";
22
import serverTiming from "@elysiajs/server-timing";
3+
import { env } from 'cloudflare:workers';
34
import Elysia from "elysia";
4-
import { CloudflareAdapter } from "elysia/adapter/cloudflare-worker";
55
import { createSetupPlugin } from "./setup";
6-
import { env } from 'cloudflare:workers'
76

8-
const basePlugin = new Elysia({
7+
const basePlugin = () => new Elysia({
98
name: "base-plugin",
10-
adapter: CloudflareAdapter
119
})
1210
.use(cors({
1311
aot: false,
@@ -24,9 +22,9 @@ const basePlugin = new Elysia({
2422
.use(serverTiming({
2523
enabled: true,
2624
}))
27-
.use(createSetupPlugin(env))
2825

2926
export default () => new Elysia({
30-
adapter: CloudflareAdapter
27+
aot: false
3128
})
32-
.use(basePlugin)
29+
.use(basePlugin())
30+
.use(createSetupPlugin(env))

server/src/server.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { TagService } from './services/tag';
1313
import { UserService } from './services/user';
1414

1515

16-
const app = base()
16+
const app = () => base()
1717
.use(UserService)
1818
.use(FaviconService)
1919
.use(FeedService)
@@ -31,7 +31,6 @@ const app = base()
3131
if (code === 'NOT_FOUND')
3232
return `${path} ${JSON.stringify(params)} not found`
3333
})
34-
.compile()
3534

3635

3736
export default app

server/src/setup.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { CacheImpl } from "./utils/cache";
77
import { drizzle } from "drizzle-orm/d1";
88
import * as schema from './db/schema';
99
import { createOAuthPlugin, GitHubProvider } from "./utils/oauth";
10+
import { CloudflareAdapter } from "elysia/adapter/cloudflare-worker";
1011

1112

1213
const anyUser = async (db: DB) => (await db.query.users.findMany())?.length > 0
@@ -47,7 +48,9 @@ export function createSetupPlugin(env: Env) {
4748
}),
4849
});
4950

50-
return new Elysia()
51+
return new Elysia({
52+
name: 'plugins',
53+
})
5154
.state('db', db)
5255
.state('env', env)
5356
.state('cache', cache)

0 commit comments

Comments
 (0)