Skip to content

Commit

Permalink
feat: improve starting the whole app (#60)
Browse files Browse the repository at this point in the history
* refactor: make starting the whole app easier and serve the web through the api
* fix: remove a duplicate field in package.json
  • Loading branch information
alikehel authored Oct 19, 2024
1 parent 42969c4 commit 4fa4404
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 44 deletions.
7 changes: 4 additions & 3 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"license": "UNLICENSED",
"scripts": {
"build": "nest build",
"start": "nest start",
"dev": "nest start --exec \"node --env-file=.env\" --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"start:old": "nest start --exec \"node --env-file=.env\"",
"start:debug": "nest start --debug --watch",
"start": "node --env-file=.env dist/src/main.js",
"typecheck": "tsc --noEmit",
"test": "jest",
"test:watch": "jest --watch",
Expand All @@ -32,6 +32,7 @@
"@nestjs/graphql": "^12.2.0",
"@nestjs/passport": "^10.0.3",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/serve-static": "^4.0.2",
"argon2": "^0.41.1",
"cache-manager": "^6.1.0",
"class-transformer": "^0.5.1",
Expand Down
5 changes: 5 additions & 0 deletions apps/api/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Module } from "@nestjs/common";
import { ConfigModule } from "@nestjs/config";
import { APP_GUARD } from "@nestjs/core";
import { GraphQLModule } from "@nestjs/graphql";
import { ServeStaticModule } from "@nestjs/serve-static";
import { Request, Response } from "express";
import { AppResolver } from "./app.resolver";
import { AppService } from "./app.service";
Expand Down Expand Up @@ -40,6 +41,10 @@ import { validate } from "./utils/env.validate";
database: String(process.env.POSTGRES_DB),
}),
AuthModule,
ServeStaticModule.forRoot({
rootPath: join(__dirname, "../../..", "web", "dist"),
exclude: ["/api*", "/graphql*"],
}),
],
providers: [
AppService,
Expand Down
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"start": "pnpm run preview",
"typecheck": "tsc -b --noEmit",
"preview": "vite preview"
},
Expand Down
28 changes: 0 additions & 28 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,9 @@ services:
- 5432:5432
env_file:
- ./apps/api/.env
# environment:
# - POSTGRES_DB
# - POSTGRES_USER
# - POSTGRES_PASSWORD

# db-test:
# image: postgres:14.1-alpine
# restart: always
# ports:
# - 5433:5432
# environment:
# POSTGRES_DB: disworse-test
# POSTGRES_USER: postgres
# POSTGRES_PASSWORD: postgres

cache:
image: redis
container_name: cache
restart: always
ports:
- 6379:6379

project:
image: node
working_dir: /app
ports:
- 3333:3333
volumes:
- .:/app
command: sh -c "scripts/entrypoint.sh"
# command: cat "scripts/entrypoint.sh"
depends_on:
- cache
- pg
15 changes: 11 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@
"scripts": {
"preinstall": "npx only-allow pnpm",
"build": "turbo build",
"dev": "turbo dev",
"build:web": "turbo build --filter web",
"build:api": "turbo build --filter api",
"dev": "pnpm run compose:up && turbo dev",
"dev:web": "turbo dev --filter web",
"dev:api": "pnpm run compose:up && turbo dev --filter api",
"start": "pnpm run compose:up && turbo build && turbo start --filter api",
"start:web": "pnpm run build:web && turbo start --filter web",
"start:api": "pnpm run compose:up && pnpm run build:api && turbo start --filter api",
"compose:up": "docker compose -f docker-compose.dev.yml up -d --build",
"compose:down": "docker compose down -v",
"typecheck": "turbo typecheck",
"lint": "biome check .",
"lint:fix": "biome check . --write",
"lint:fix:unsafe": "biome check . --write --unsafe",
"prepare": "husky",
"commitlint": "commitlint --edit",
"compose:up": "docker compose -f docker-compose.dev.yml up -d --build",
"compose:down": "docker compose down -v"
"commitlint": "commitlint --edit"
},
"lint-staged": {
"**/*": ["biome check . --write"]
Expand Down
32 changes: 32 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 0 additions & 9 deletions scripts/entrypoint.sh

This file was deleted.

5 changes: 5 additions & 0 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
"cache": false,
"persistent": true
},
"start": {
"dependsOn": ["^build"],
"inputs": ["$TURBO_DEFAULT$", ".env*"],
"outputs": ["dist/**"]
},
"typecheck": {
"cache": false
},
Expand Down

0 comments on commit 4fa4404

Please sign in to comment.