diff --git a/server/app.js b/server/app.js index 03eaf0d..8adb5c5 100755 --- a/server/app.js +++ b/server/app.js @@ -10,11 +10,11 @@ import nconf from 'nconf'; import yaml from 'js-yaml'; import { SitespeedioServer } from './src/server.js'; -import { getLocalFilePath } from './src/util/fileutil.js'; +import { getBaseFilePath } from './src/util/fileutil.js'; const require = createRequire(import.meta.url); const version = require('./package.json').version; -const defaultConfig = getLocalFilePath('../../config/default.yaml'); +const defaultConfig = getBaseFilePath('./config/default.yaml'); nconf.argv(); diff --git a/server/src/util/add-test.js b/server/src/util/add-test.js index eeb3955..3f3be84 100644 --- a/server/src/util/add-test.js +++ b/server/src/util/add-test.js @@ -19,7 +19,7 @@ import { getDeviceQueue } from '../queuehandler.js'; import { setConfigById } from '../configs.js'; -import { getLocalFilePath } from './fileutil.js'; +import { getBaseFilePath } from './fileutil.js'; const logger = log.getLogger('sitespeedio.server'); @@ -31,7 +31,7 @@ async function getDefaultSitespeedConfiguration() { return JSON.parse(result.toString()); } const result = await readFile( - path.resolve(getLocalFilePath('../../config/sitespeed.json')) + path.resolve(getBaseFilePath('./config/sitespeed.json')) ); return JSON.parse(result.toString()); } diff --git a/server/src/util/fileutil.js b/server/src/util/fileutil.js index b3960c2..4db6fe9 100644 --- a/server/src/util/fileutil.js +++ b/server/src/util/fileutil.js @@ -3,9 +3,9 @@ import { dirname } from 'node:path'; import { fileURLToPath } from 'node:url'; import path from 'node:path'; -export function getLocalFilePath(thePath) { +export function getBaseFilePath(theFile) { const currentFileUrl = import.meta.url; const currentFilePath = fileURLToPath(currentFileUrl); const currentDirectory = dirname(currentFilePath); - return path.resolve(currentDirectory, thePath); + return path.resolve(currentDirectory, '../../', theFile); } diff --git a/server/src/util/text.js b/server/src/util/text.js index ee9ee8a..e50bd2a 100644 --- a/server/src/util/text.js +++ b/server/src/util/text.js @@ -1,9 +1,9 @@ import nconf from 'nconf'; import y18n from 'y18n'; -import { getLocalFilePath } from './fileutil.js'; +import { getBaseFilePath } from './fileutil.js'; const locale = nconf.get('localization:defaultLocale'); const directory = - nconf.get('localization:directory') || getLocalFilePath('../../locales'); + nconf.get('localization:directory') || getBaseFilePath('./locales'); const myy18n = y18n({ updateFiles: false, locale, directory }); diff --git a/server/src/webserver.js b/server/src/webserver.js index b8e6761..a69b2ed 100755 --- a/server/src/webserver.js +++ b/server/src/webserver.js @@ -25,7 +25,7 @@ import { api } from './routes/api/api.js'; import { BasicAuth } from './middleware/basicauth.js'; import { error404, error500 } from './middleware/errorhandler.js'; import { setupStatic } from './static/index.js'; -import { getLocalFilePath } from './util/fileutil.js'; +import { getBaseFilePath } from './util/fileutil.js'; const logger = log.getLogger('sitespeedio.server'); @@ -46,7 +46,7 @@ function setupExpressServer() { app.use(express.json()); app.set('view engine', 'pug'); - app.set('views', path.resolve(getLocalFilePath('../../views'))); + app.set('views', path.resolve(getBaseFilePath('./views'))); app.enable('view cache'); diff --git a/testrunner/app.js b/testrunner/app.js index cf79c36..6d86eb1 100755 --- a/testrunner/app.js +++ b/testrunner/app.js @@ -15,9 +15,9 @@ const version = require('./package.json').version; import { SitespeedioTestRunner } from './src/sitespeedio-testrunner.js'; import { validate } from './src/validateconfig.js'; -import { getLocalFilePath } from './src/util.js'; +import { getBaseFilePath } from './src/util.js'; -const defaultConfig = getLocalFilePath('../config/default.yaml'); +const defaultConfig = getBaseFilePath('./config/default.yaml'); function getFilteredConfig() { const config = nconf.get(); diff --git a/testrunner/src/testrunners/testrunner.js b/testrunner/src/testrunners/testrunner.js index 6b5f140..2e82c32 100644 --- a/testrunner/src/testrunners/testrunner.js +++ b/testrunner/src/testrunners/testrunner.js @@ -7,7 +7,7 @@ import log from 'intel'; import nconf from 'nconf'; import { queueHandler } from '../queue/queuehandler.js'; -import { getLocalFilePath } from '../util.js'; +import { getBaseFilePath } from '../util.js'; const { join } = path; /** @@ -103,7 +103,7 @@ function prepareSitespeedConfig(job) { jobConfig.extends = nconf.get('sitespeedioConfigFile') === undefined - ? getLocalFilePath('../config/sitespeedDefault.json') + ? getBaseFilePath('./config/sitespeedDefault.json') : path.resolve(nconf.get('sitespeedioConfigFile')); return jobConfig; diff --git a/testrunner/src/util.js b/testrunner/src/util.js index b3960c2..67930b2 100644 --- a/testrunner/src/util.js +++ b/testrunner/src/util.js @@ -3,9 +3,9 @@ import { dirname } from 'node:path'; import { fileURLToPath } from 'node:url'; import path from 'node:path'; -export function getLocalFilePath(thePath) { +export function getBaseFilePath(theFile) { const currentFileUrl = import.meta.url; const currentFilePath = fileURLToPath(currentFileUrl); const currentDirectory = dirname(currentFilePath); - return path.resolve(currentDirectory, thePath); + return path.resolve(currentDirectory, '../', theFile); }