fix(backend): crashes due to logger and missing server-stubs files

This commit is contained in:
2026-09-07 16:14:13 +02:00
parent 18bdf82bcf
commit cb5cdc483f
4 changed files with 30 additions and 8 deletions
+1
View File
@@ -0,0 +1 @@
{"playlists":[],"userid":"server-stubs","version":"1"}
+3
View File
@@ -8,6 +8,7 @@ import {
import devtoken from './routes/devtoken'; import devtoken from './routes/devtoken';
import express from 'express'; import express from 'express';
import fs from 'fs'; import fs from 'fs';
import logger from './logger';
import path from 'path'; import path from 'path';
import room from './routes/room'; import room from './routes/room';
import user from './routes/user'; import user from './routes/user';
@@ -26,6 +27,8 @@ const run = () => {
const storeSdk = getStoreSdk( foss ); const storeSdk = getStoreSdk( foss );
const app = express(); const app = express();
app.use( logger.routeLogging() );
// Load id.janishutz.com SDK and allow signing in // Load id.janishutz.com SDK and allow signing in
sdk.setUp( sdk.setUp(
{ {
+16 -7
View File
@@ -1,29 +1,37 @@
import express from 'express';
import { import {
writeFile writeFile
} from 'node:fs'; } from 'node:fs';
const log = ( ...msg: unknown[] ) => { const log = ( ...msg: unknown[] ) => {
output( 'log', log.caller.toString(), ...msg ); output( 'log', 'UNKNOWN', ...msg );
}; };
const info = ( ...msg: unknown[] ) => { const info = ( ...msg: unknown[] ) => {
output( 'info', log.caller.toString(), ...msg ); output( 'info', 'UNKNOWN', ...msg );
}; };
const debug = ( ...msg: unknown[] ) => { const debug = ( ...msg: unknown[] ) => {
output( 'debug', log.caller.toString(), ...msg ); output( 'debug', 'UNKNOWN', ...msg );
}; };
const warn = ( ...msg: unknown[] ) => { const warn = ( ...msg: unknown[] ) => {
output( 'warn', log.caller.toString(), ...msg ); output( 'warn', 'UNKNOWN', ...msg );
}; };
const error = ( ...msg: unknown[] ) => { const error = ( ...msg: unknown[] ) => {
output( 'error', log.caller.toString(), ...msg ); output( 'error', 'UNKNOWN', ...msg );
}; };
const fatal = ( ...msg: unknown[] ) => { const fatal = ( ...msg: unknown[] ) => {
output( 'fatal', log.caller.toString(), ...msg ); output( 'fatal', 'UNKNOWN', ...msg );
};
const routeLogging = () => {
return ( request: express.Request, _response: express.Response, next: express.NextFunction ) => {
output( 'info', 'ROUTER', request.originalUrl, 'from', request.headers['user-agent'] ?? 'No UA' );
next();
};
}; };
@@ -100,5 +108,6 @@ export default {
warn, warn,
error, error,
fatal, fatal,
configure configure,
routeLogging
}; };
+10 -1
View File
@@ -18,6 +18,14 @@ export const getUserFile = async ( uid: string ): Promise<UserPlaylistFile> => {
} ); } );
}; };
const createUserFile = async ( uid: string ): Promise<void> => {
writeUserFile( uid, {
'playlists': [],
'userid': uid,
'version': '1'
} );
};
export const getUserFilePath = ( uid: string ): string => { export const getUserFilePath = ( uid: string ): string => {
return path.join( __dirname, '/../../../data/', uid + '.json' ); return path.join( __dirname, '/../../../data/', uid + '.json' );
}; };
@@ -43,5 +51,6 @@ export default {
getUserFilePath, getUserFilePath,
getUserFile, getUserFile,
writeUserFile, writeUserFile,
testUserFileExists testUserFileExists,
createUserFile
}; };