chore: fix startup of backend

This commit is contained in:
2026-08-26 10:47:10 +02:00
parent 94906c3499
commit 4c5e1a864b
3 changed files with 65 additions and 53 deletions
+47 -40
View File
@@ -4,51 +4,58 @@ import fs from 'fs';
import jwt from 'jsonwebtoken'; import jwt from 'jsonwebtoken';
import path from 'path'; import path from 'path';
const app = express();
app.use( expressSession( { const run = () => {
'secret': '', const app = express();
'resave': true,
'saveUninitialized': false app.use( expressSession( {
} ) ); 'secret': '',
'resave': true,
'saveUninitialized': false
} ) );
app.get( '/', ( request: express.Request, response: express.Response ) => { app.get( '/', ( request: express.Request, response: express.Response ) => {
response.send( 'HELLO WORLD' ); response.send( 'HELLO WORLD' );
} );
const privateKey = fs.readFileSync( path.join(
__dirname,
'/config/apple_private_key.p8'
) ).toString();
const musicApiConfig = JSON.parse( fs.readFileSync( path.join(
__dirname,
'/config/apple-music-api.config.secret.json'
) ).toString() );
app.get( '/dev-token', ( request: express.Request, response: express.Response ) => {
// sign dev token
const now = new Date().getTime();
const tomorrow = now + ( 24 * 3600 * 1000 );
const jwtToken = jwt.sign( {
'iss': musicApiConfig.teamID,
'iat': Math.floor( now / 1000 ),
'exp': Math.floor( tomorrow / 1000 )
}, privateKey, {
'algorithm': 'ES256',
'keyid': musicApiConfig.keyID
} ); } );
response.send( jwtToken );
} );
app.use( ( _request: express.Request, response: express.Response ) => {
response.sendFile( path.join( __dirname, '' ) );
} );
const PORT = process.env.PORT || 8080; const privateKey = fs.readFileSync( path.join(
__dirname,
'/config/apple_private_key.p8'
) ).toString();
const musicApiConfig = JSON.parse( fs.readFileSync( path.join(
__dirname,
'/config/apple-music-api.config.secret.json'
) ).toString() );
app.listen( PORT ); app.get( '/dev-token', ( request: express.Request, response: express.Response ) => {
// sign dev token
const now = new Date().getTime();
const tomorrow = now + ( 24 * 3600 * 1000 );
const jwtToken = jwt.sign( {
'iss': musicApiConfig.teamID,
'iat': Math.floor( now / 1000 ),
'exp': Math.floor( tomorrow / 1000 )
}, privateKey, {
'algorithm': 'ES256',
'keyid': musicApiConfig.keyID
} );
response.send( jwtToken );
} );
app.use( ( _request: express.Request, response: express.Response ) => {
response.sendFile( path.join( __dirname, '' ) );
} );
const PORT = process.env.PORT || 8080;
app.listen( PORT );
};
export default {
run
};
+1 -1
View File
@@ -44,7 +44,7 @@ const configure = ( location: 'stderr' | 'file', minLevel: LogLevel, file?: stri
throw new Error( 'File parameter required when location is "file"' ); throw new Error( 'File parameter required when location is "file"' );
} }
loc = location === 'stderr' ? 'stderr' : file; loc = location === 'stderr' ? 'stderr' : ( file ?? 'musicplayer.log' );
lev = levels.indexOf( minLevel ); lev = levels.indexOf( minLevel );
}; };
+17 -12
View File
@@ -1,13 +1,18 @@
{ {
"compilerOptions": { "compilerOptions": {
"outDir": "./dist", "outDir": "./dist",
"allowJs": true, "rootDir": "./src",
"target": "ES6", "allowJs": true,
"skipLibCheck": true, "target": "ES6",
"allowSyntheticDefaultImports": true, "skipLibCheck": true,
"types": ["node"], "allowSyntheticDefaultImports": true,
"module": "NodeNext", "types": [
"moduleResolution": "NodeNext" "node"
}, ],
"include": [ "./src/**/*" ], "module": "NodeNext",
} "moduleResolution": "NodeNext"
},
"include": [
"./src/**/*"
]
}