@@ -3,14 +3,14 @@ import { defu } from 'defu'
3
3
import { generateDeveloperToken } from './runtime/server/utils/musicKit'
4
4
5
5
// Module options TypeScript interface definition
6
- type ModuleOptions = {
7
- clientModeOnly : boolean ;
6
+ export type ModuleOptions = {
7
+ clientModeOnly ? : boolean ;
8
8
appName : string ;
9
9
appBuild : string ;
10
10
devTokenUrl ?: string ;
11
+ developerKey ?: string ;
11
12
teamID ?: string ;
12
13
keyID ?: string ;
13
- developerKey ?: string ;
14
14
} ;
15
15
16
16
declare global {
@@ -53,12 +53,6 @@ export default defineNuxtModule<ModuleOptions>({
53
53
nuxt . options . runtimeConfig . musicKit = defu ( nuxt . options . runtimeConfig . musicKit || { } , options )
54
54
const musicKitOptions = nuxt . options . runtimeConfig . musicKit as ModuleOptions
55
55
56
- if ( musicKitOptions . devTokenUrl && ! musicKitOptions . devTokenUrl . startsWith ( 'http://' ) && ! musicKitOptions . devTokenUrl . startsWith ( 'https://' ) ) {
57
- addServerHandler ( {
58
- route : musicKitOptions . devTokenUrl ,
59
- handler : resolver . resolve ( './runtime/server/api/token' ) ,
60
- } )
61
- }
62
56
if ( musicKitOptions . clientModeOnly && musicKitOptions . devTokenUrl ) {
63
57
try {
64
58
const response = await fetch ( musicKitOptions . devTokenUrl ) ;
@@ -74,6 +68,13 @@ export default defineNuxtModule<ModuleOptions>({
74
68
} else if ( musicKitOptions . developerKey && musicKitOptions . teamID && musicKitOptions . keyID ) {
75
69
try {
76
70
token = await generateDeveloperToken ( musicKitOptions . developerKey , musicKitOptions . teamID , musicKitOptions . keyID ) ;
71
+ if ( musicKitOptions . devTokenUrl && ! musicKitOptions . devTokenUrl . startsWith ( 'http://' ) && ! musicKitOptions . devTokenUrl . startsWith ( 'https://' ) ) {
72
+ addServerHandler ( {
73
+ route : musicKitOptions . devTokenUrl ,
74
+ handler : resolver . resolve ( './runtime/server/api/token' ) ,
75
+ } )
76
+ }
77
+
77
78
} catch ( error ) {
78
79
console . warn ( 'Failed to generate Apple Music developer token:' , error ) ;
79
80
console . warn ( 'MusicKit functionality will be limited without a valid token' ) ;
0 commit comments