mirror of
https://github.com/janishutz/MusicPlayer.git
synced 2026-09-10 14:25:24 +02:00
fix(backend): crashes due to logger and missing server-stubs files
This commit is contained in:
@@ -0,0 +1 @@
|
||||
{"playlists":[],"userid":"server-stubs","version":"1"}
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
import devtoken from './routes/devtoken';
|
||||
import express from 'express';
|
||||
import fs from 'fs';
|
||||
import logger from './logger';
|
||||
import path from 'path';
|
||||
import room from './routes/room';
|
||||
import user from './routes/user';
|
||||
@@ -26,6 +27,8 @@ const run = () => {
|
||||
const storeSdk = getStoreSdk( foss );
|
||||
const app = express();
|
||||
|
||||
app.use( logger.routeLogging() );
|
||||
|
||||
// Load id.janishutz.com SDK and allow signing in
|
||||
sdk.setUp(
|
||||
{
|
||||
|
||||
+16
-7
@@ -1,29 +1,37 @@
|
||||
import express from 'express';
|
||||
import {
|
||||
writeFile
|
||||
} from 'node:fs';
|
||||
|
||||
const log = ( ...msg: unknown[] ) => {
|
||||
output( 'log', log.caller.toString(), ...msg );
|
||||
output( 'log', 'UNKNOWN', ...msg );
|
||||
};
|
||||
|
||||
const info = ( ...msg: unknown[] ) => {
|
||||
output( 'info', log.caller.toString(), ...msg );
|
||||
output( 'info', 'UNKNOWN', ...msg );
|
||||
};
|
||||
|
||||
const debug = ( ...msg: unknown[] ) => {
|
||||
output( 'debug', log.caller.toString(), ...msg );
|
||||
output( 'debug', 'UNKNOWN', ...msg );
|
||||
};
|
||||
|
||||
const warn = ( ...msg: unknown[] ) => {
|
||||
output( 'warn', log.caller.toString(), ...msg );
|
||||
output( 'warn', 'UNKNOWN', ...msg );
|
||||
};
|
||||
|
||||
const error = ( ...msg: unknown[] ) => {
|
||||
output( 'error', log.caller.toString(), ...msg );
|
||||
output( 'error', 'UNKNOWN', ...msg );
|
||||
};
|
||||
|
||||
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,
|
||||
error,
|
||||
fatal,
|
||||
configure
|
||||
configure,
|
||||
routeLogging
|
||||
};
|
||||
|
||||
@@ -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 => {
|
||||
return path.join( __dirname, '/../../../data/', uid + '.json' );
|
||||
};
|
||||
@@ -43,5 +51,6 @@ export default {
|
||||
getUserFilePath,
|
||||
getUserFile,
|
||||
writeUserFile,
|
||||
testUserFileExists
|
||||
testUserFileExists,
|
||||
createUserFile
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user