mirror of
https://github.com/janishutz/MusicPlayer.git
synced 2026-09-10 14:25:24 +02:00
chore: fix startup of backend
This commit is contained in:
+47
-40
@@ -4,51 +4,58 @@ import fs from 'fs';
|
||||
import jwt from 'jsonwebtoken';
|
||||
import path from 'path';
|
||||
|
||||
const app = express();
|
||||
|
||||
app.use( expressSession( {
|
||||
'secret': '',
|
||||
'resave': true,
|
||||
'saveUninitialized': false
|
||||
} ) );
|
||||
const run = () => {
|
||||
const app = express();
|
||||
|
||||
app.use( expressSession( {
|
||||
'secret': '',
|
||||
'resave': true,
|
||||
'saveUninitialized': false
|
||||
} ) );
|
||||
|
||||
|
||||
app.get( '/', ( request: express.Request, response: express.Response ) => {
|
||||
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
|
||||
app.get( '/', ( request: express.Request, response: express.Response ) => {
|
||||
response.send( 'HELLO WORLD' );
|
||||
} );
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
@@ -44,7 +44,7 @@ const configure = ( location: 'stderr' | 'file', minLevel: LogLevel, file?: stri
|
||||
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 );
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user