From c1905d7a24056616fe70056260afb1f9640ec5f4 Mon Sep 17 00:00:00 2001 From: JustMichael Date: Sat, 30 Mar 2024 12:17:45 +0000 Subject: [PATCH] fix: fix paths and dev enviornment --- .devcontainer/docker-compose.yml | 1 + package.json | 4 ++-- pkg/api/audit.json | 16 ---------------- pkg/api/package.json | 2 +- pkg/api/src/api/routes/web.ts | 1 - pkg/api/src/config/env/paths.ts | 10 ++++++---- pkg/api/src/config/env/views.ts | 2 -- 7 files changed, 10 insertions(+), 26 deletions(-) delete mode 100644 pkg/api/audit.json diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index 43ba7c3c1..3c77a727e 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -22,6 +22,7 @@ services: - TZ=Europe\London - DB_URL=mongodb://mongo:27017/petio - SSH_AUTH_SOCK=/ssh-agent + - NODE_ENV=development entrypoint: ['zsh', '-c', 'while sleep 1000; do :; done'] mongo: diff --git a/package.json b/package.json index 7284c9fe0..ec67008d5 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "private": true, "author": "Petio Team", "license": "MIT", - "bin": "./pkg/api/dist/index.js", + "bin": "./dist/api/index.js", "workspaces": [ "pkg/api", "pkg/frontend", @@ -38,7 +38,7 @@ "node16-windows-x64", "node16-windows-arm64" ], - "outputPath": "dist" + "outputPath": "dist/releases" }, "packageManager": "yarn@3.2.1" } diff --git a/pkg/api/audit.json b/pkg/api/audit.json deleted file mode 100644 index 21ab71ea8..000000000 --- a/pkg/api/audit.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "keepSettings": { - "type": 1, - "amount": 7 - }, - "auditFilename": "audit.json", - "hashType": "md5", - "extension": "", - "files": [ - { - "date": 1711739330003, - "name": "/workspace/pkg/api/data/logs/petio-2024-03-29.log", - "hash": "6e92f6892d5452b65bc772cb222e273e" - } - ] -} \ No newline at end of file diff --git a/pkg/api/package.json b/pkg/api/package.json index 00f722f37..2b0dd5ea6 100644 --- a/pkg/api/package.json +++ b/pkg/api/package.json @@ -8,7 +8,7 @@ "watch": "nodemon", "inspect": "nodemon --exec \"node --require tsconfig-paths/register --require ts-node/register --inspect ./src/app.ts\"", "build": "tsc && tsc-alias", - "build:prod": "yarn ncc -t build ./src/app.ts -o dist -m", + "build:prod": "yarn ncc -t build ./src/app.ts -o ../../dist/api -m", "test": "ts-mocha --paths src/**/*.test.ts", "depcheck": "depcheck", "lint": "eslint . --ext .ts", diff --git a/pkg/api/src/api/routes/web.ts b/pkg/api/src/api/routes/web.ts index 24e62ad13..c2a3b3aaa 100644 --- a/pkg/api/src/api/routes/web.ts +++ b/pkg/api/src/api/routes/web.ts @@ -23,7 +23,6 @@ function serveReact(app: Koa, dir: string, urlPath: string) { app.use(mount(urlPath, spa)); } - export default async (app: Koa) => { let frontendPath = viewsConfig.frontend; if (!(await pathExists(path.join(frontendPath, 'index.html')))) { diff --git a/pkg/api/src/config/env/paths.ts b/pkg/api/src/config/env/paths.ts index adc9b4e43..c7dc0f919 100644 --- a/pkg/api/src/config/env/paths.ts +++ b/pkg/api/src/config/env/paths.ts @@ -1,5 +1,9 @@ import path from "path"; +// ! This is a workaround for the fact that the process.cwd() is not the same as the root directory of the project +// ! because pkg from vercel adds an additional pkg field that points to the root directory of the project +const proc: Process = process; + type PathsConfig = { rootDir: string; appDir: string; @@ -7,10 +11,8 @@ type PathsConfig = { viewsDir: string; }; -const proc: Process = process; - -const ROOT_DIR = proc.cwd(); -const APP_DIR = proc.env.APP_DIR ?? path.join(__dirname, '../../..'); +const ROOT_DIR = proc.pkg ? proc.cwd() : path.join(__dirname, '../../../../..'); +const APP_DIR = proc.pkg ? path.join(__dirname, "../..") : (proc.env.APP_DIR ?? path.join(__dirname, '../../../../..')); const VIEWS_DIR = process.env.VIEWS_FOLDER ?? path.join(APP_DIR, './pkg'); const DATA_DIR = process.env.DATA_FOLDER ?? path.join(ROOT_DIR, './data'); diff --git a/pkg/api/src/config/env/views.ts b/pkg/api/src/config/env/views.ts index e4dd71084..444731d59 100644 --- a/pkg/api/src/config/env/views.ts +++ b/pkg/api/src/config/env/views.ts @@ -3,12 +3,10 @@ import pathConfig from "./paths"; type ViewsConfig = { frontend: string; - admin: string; }; const viewsConfig: ViewsConfig = { frontend: path.join(pathConfig.viewsDir, "./frontend"), - admin: path.join(pathConfig.viewsDir, "./admin"), }; export default viewsConfig;