1
0
forked from noxious/server

Path fixes for all environments, npm run format, removed redundant imports

This commit is contained in:
2024-10-01 00:10:30 +02:00
parent 4cbd62cbb0
commit ce1708a55e
24 changed files with 82 additions and 87 deletions

View File

@ -12,6 +12,7 @@ import fs from 'fs'
import zoneRepository from '../repositories/zoneRepository'
import zoneManager from '../managers/zoneManager'
import { httpLogger } from './logger'
import { getPublicPath } from './utilities'
async function addHttpRoutes(app: Application) {
/**
@ -117,9 +118,9 @@ async function addHttpRoutes(app: Application) {
let assetPath
if (assetType === 'sprites' && spriteId) {
assetPath = path.join(process.cwd(), 'public', assetType, spriteId, fileName)
assetPath = getPublicPath(assetType, spriteId, fileName)
} else {
assetPath = path.join(process.cwd(), 'public', assetType, fileName)
assetPath = getPublicPath(assetType, fileName)
}
if (!fs.existsSync(assetPath)) {

View File

@ -1,6 +1,6 @@
import pino from 'pino'
import fs from 'fs'
import path from 'path'
import { getRootPath } from './utilities'
// Array of log types
const LOG_TYPES = ['http', 'game', 'gameMaster', 'app', 'queue', 'command'] as const
@ -30,7 +30,7 @@ const loggers = Object.fromEntries(LOG_TYPES.map((type) => [type, createLogger(t
const watchLogs = () => {
LOG_TYPES.forEach((type) => {
const logFile = path.join(__dirname, '../../logs', `${type}.log`)
const logFile = getRootPath('logs', `${type}.log`)
fs.watchFile(logFile, (curr, prev) => {
if (curr.size > prev.size) {

View File

@ -0,0 +1,15 @@
import config from './config'
import path from 'path'
export function getRootPath(folder: string, ...additionalSegments: string[]) {
return path.join(process.cwd(), folder, ...additionalSegments)
}
export function getAppPath(folder: string, ...additionalSegments: string[]) {
const baseDir = config.ENV === 'development' ? 'src' : 'dist'
return path.join(process.cwd(), baseDir, folder, ...additionalSegments)
}
export function getPublicPath(folder: string, ...additionalSegments: string[]) {
return path.join(process.cwd(), 'public', folder, ...additionalSegments)
}