chore: prepare backend

This commit is contained in:
2026-09-03 08:46:53 +02:00
parent 223478f7cc
commit c123673ca5
9 changed files with 161 additions and 42 deletions
+6 -33
View File
@@ -1,14 +1,13 @@
import cors from 'cors';
import devtoken from './routes/devtoken';
import express from 'express';
import expressSession from 'express-session';
import fs from 'fs';
import jwt from 'jsonwebtoken';
import path from 'path';
const run = () => {
const app = express();
// TODO: Use db store for this (via sdk or stubs)
app.use( expressSession( {
'secret': 'dev',
'resave': true,
@@ -16,45 +15,19 @@ const run = () => {
} ) );
app.get( '/', ( request: express.Request, response: express.Response ) => {
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', cors( {
'origin': 'http://localhost:8081',
'credentials': true
} ), ( _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, '' ) );
} );
devtoken.routes( app );
const PORT = process.env.PORT || 8080;
app.listen( PORT );