forked from noxious/server
Mass replace parameter order (socket,io)>(io,socket), worked on queueing system
This commit is contained in:
@ -75,29 +75,33 @@ async function addHttpRoutes(app: Application) {
|
||||
*/
|
||||
app.get('/assets/zone/:zoneId', async (req: Request, res: Response) => {
|
||||
const zoneId = req.params.zoneId
|
||||
if(!zoneId || parseInt(zoneId) === 0) {
|
||||
if (!zoneId || parseInt(zoneId) === 0) {
|
||||
return res.status(400).json({ message: 'Invalid zone ID' })
|
||||
}
|
||||
|
||||
const zone = await zoneRepository.getById(parseInt(zoneId))
|
||||
if(!zone) {
|
||||
if (!zone) {
|
||||
return res.status(404).json({ message: 'Zone not found' })
|
||||
}
|
||||
|
||||
const assets = await zoneManager.getZoneAssets(zone);
|
||||
const assets = await zoneManager.getZoneAssets(zone)
|
||||
|
||||
res.json([
|
||||
...assets.tiles.map(x => { return {
|
||||
key: x,
|
||||
url: '/assets/tiles/' + x + '.png',
|
||||
group: 'tiles'
|
||||
}}),
|
||||
...assets.objects.map(x => { return {
|
||||
key: x,
|
||||
url: '/assets/objects/' + x + '.png',
|
||||
group: 'objects'
|
||||
}})
|
||||
]);
|
||||
...assets.tiles.map((x) => {
|
||||
return {
|
||||
key: x,
|
||||
url: '/assets/tiles/' + x + '.png',
|
||||
group: 'tiles'
|
||||
}
|
||||
}),
|
||||
...assets.objects.map((x) => {
|
||||
return {
|
||||
key: x,
|
||||
url: '/assets/objects/' + x + '.png',
|
||||
group: 'objects'
|
||||
}
|
||||
})
|
||||
])
|
||||
})
|
||||
|
||||
/**
|
||||
|
@ -3,46 +3,46 @@ import fs from 'fs'
|
||||
import path from 'path'
|
||||
|
||||
// Array of log types
|
||||
const LOG_TYPES = ['http', 'game', 'gameMaster', 'app'] as const
|
||||
type LogType = typeof LOG_TYPES[number]
|
||||
const LOG_TYPES = ['http', 'game', 'gameMaster', 'app', 'queue'] as const
|
||||
type LogType = (typeof LOG_TYPES)[number]
|
||||
|
||||
const createLogger = (name: LogType) => pino({
|
||||
level: process.env.LOG_LEVEL || 'debug',
|
||||
transport: {
|
||||
target: 'pino/file',
|
||||
options: {
|
||||
destination: `./logs/${name}.log`,
|
||||
mkdir: true
|
||||
}
|
||||
},
|
||||
formatters: {
|
||||
level: (label) => {
|
||||
return { level: label.toUpperCase() }
|
||||
}
|
||||
},
|
||||
timestamp: pino.stdTimeFunctions.isoTime,
|
||||
base: null
|
||||
})
|
||||
const createLogger = (name: LogType) =>
|
||||
pino({
|
||||
level: process.env.LOG_LEVEL || 'debug',
|
||||
transport: {
|
||||
target: 'pino/file',
|
||||
options: {
|
||||
destination: `./logs/${name}.log`,
|
||||
mkdir: true
|
||||
}
|
||||
},
|
||||
formatters: {
|
||||
level: (label) => {
|
||||
return { level: label.toUpperCase() }
|
||||
}
|
||||
},
|
||||
timestamp: pino.stdTimeFunctions.isoTime,
|
||||
base: null
|
||||
})
|
||||
|
||||
// Create logger instances
|
||||
const loggers = Object.fromEntries(
|
||||
LOG_TYPES.map(type => [type, createLogger(type)])
|
||||
) as Record<LogType, ReturnType<typeof createLogger>>
|
||||
const loggers = Object.fromEntries(LOG_TYPES.map((type) => [type, createLogger(type)])) as Record<LogType, ReturnType<typeof createLogger>>
|
||||
|
||||
const watchLogs = () => {
|
||||
LOG_TYPES.forEach(type => {
|
||||
LOG_TYPES.forEach((type) => {
|
||||
const logFile = path.join(__dirname, '../../logs', `${type}.log`)
|
||||
|
||||
fs.watchFile(logFile, (curr, prev) => {
|
||||
if (curr.size > prev.size) {
|
||||
const stream = fs.createReadStream(logFile, { start: prev.size, end: curr.size })
|
||||
stream.on('data', (chunk) => {
|
||||
console.log(`[${type}] \n ${chunk.toString()}`)
|
||||
console.log(`[${type}]\n${chunk.toString()}`)
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export const { http: httpLogger, game: gameLogger, gameMaster: gameMasterLogger, app: appLogger } = loggers
|
||||
export { watchLogs }
|
||||
export const { http: httpLogger, game: gameLogger, gameMaster: gameMasterLogger, app: appLogger, queue: queueLogger } = loggers
|
||||
|
||||
export { watchLogs }
|
||||
|
Reference in New Issue
Block a user