Skip to content

Commit 33a09cc

Browse files
committed
fix(api-server): fix #3572
1 parent e2c849f commit 33a09cc

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/plugins/api-server/backend/main.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const backend = createBackend<BackendType, APIServerConfig>({
1919
async start(ctx) {
2020
const config = await ctx.getConfig();
2121

22-
await this.init(ctx);
22+
this.init(ctx);
2323
registerCallback((songInfo) => {
2424
this.songInfo = songInfo;
2525
});
@@ -60,8 +60,7 @@ export const backend = createBackend<BackendType, APIServerConfig>({
6060
},
6161

6262
// Custom
63-
async init(ctx) {
64-
const config = await ctx.getConfig();
63+
init(backendCtx) {
6564
this.app = new Hono();
6665

6766
this.app.use('*', cors());
@@ -74,6 +73,8 @@ export const backend = createBackend<BackendType, APIServerConfig>({
7473

7574
// middlewares
7675
this.app.use('/api/*', async (ctx, next) => {
76+
const config = await backendCtx.getConfig();
77+
7778
if (config.authStrategy !== AuthStrategy.NONE) {
7879
return await jwt({
7980
secret: config.secret,
@@ -83,6 +84,7 @@ export const backend = createBackend<BackendType, APIServerConfig>({
8384
});
8485
this.app.use('/api/*', async (ctx, next) => {
8586
const result = await JWTPayloadSchema.spa(await ctx.get('jwtPayload'));
87+
const config = await backendCtx.getConfig();
8688

8789
const isAuthorized =
8890
config.authStrategy === AuthStrategy.NONE ||
@@ -98,12 +100,12 @@ export const backend = createBackend<BackendType, APIServerConfig>({
98100
// routes
99101
registerControl(
100102
this.app,
101-
ctx,
103+
backendCtx,
102104
() => this.songInfo,
103105
() => this.currentRepeatMode,
104106
() => this.volume,
105107
);
106-
registerAuth(this.app, ctx);
108+
registerAuth(this.app, backendCtx);
107109

108110
// swagger
109111
this.app.openAPIRegistry.registerComponent(

src/plugins/api-server/backend/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export type BackendType = {
1515
currentRepeatMode?: RepeatMode;
1616
volume?: number;
1717

18-
init: (ctx: BackendContext<APIServerConfig>) => Promise<void>;
18+
init: (ctx: BackendContext<APIServerConfig>) => void;
1919
run: (hostname: string, port: number) => void;
2020
end: () => void;
2121
};

0 commit comments

Comments
 (0)