Finalize template
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -36,6 +36,10 @@ npm-debug.log
|
|||||||
yarn-error.log
|
yarn-error.log
|
||||||
testem.log
|
testem.log
|
||||||
/typings
|
/typings
|
||||||
|
pnpm-debug.log
|
||||||
|
pnpm-error.log
|
||||||
|
package-lock.json
|
||||||
|
.pnpm-store/
|
||||||
|
|
||||||
# System Files
|
# System Files
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|||||||
17
apps/api/Dockerfile.dev
Normal file
17
apps/api/Dockerfile.dev
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
FROM node:20-bookworm-slim
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
RUN corepack enable
|
||||||
|
|
||||||
|
# Dependencies (from workspace root)
|
||||||
|
COPY package.json pnpm-lock.yaml ./
|
||||||
|
RUN pnpm install
|
||||||
|
|
||||||
|
# Monorepo structure
|
||||||
|
COPY nx.json tsconfig.base.json ./
|
||||||
|
COPY apps/api ./apps/api
|
||||||
|
COPY libs ./libs
|
||||||
|
COPY prisma ./prisma
|
||||||
|
|
||||||
|
ENV PORT=3000
|
||||||
|
CMD ["pnpm", "nx", "serve", "api"]
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { AppController } from './app.controller';
|
import { AppController } from './app.controller';
|
||||||
import { AppService } from './app.service';
|
import { AppService } from './app.service';
|
||||||
|
import { PostsModule } from '../modules/users/posts.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [],
|
imports: [PostsModule],
|
||||||
controllers: [AppController],
|
controllers: [AppController],
|
||||||
providers: [AppService],
|
providers: [AppService],
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import { Controller, Get, NotFoundException, Param } from '@nestjs/common';
|
||||||
|
import { Post } from '@shared/prisma-generated/src/types';
|
||||||
|
import { prisma } from '@shared/prisma-generated/src/prisma';
|
||||||
|
|
||||||
|
@Controller('posts')
|
||||||
|
export class PostsController {
|
||||||
|
@Get()
|
||||||
|
async findAll(): Promise<Post[]> {
|
||||||
|
const posts = await prisma.post.findMany();
|
||||||
|
return posts;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get(':id')
|
||||||
|
async findById(@Param('id') id: string): Promise<Post> {
|
||||||
|
const post = await prisma.post.findUnique({
|
||||||
|
where: { id },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!post) {
|
||||||
|
throw new NotFoundException(`Post with id ${id} not found`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return post;
|
||||||
|
}
|
||||||
|
}
|
||||||
7
apps/api/src/modules/users/posts.module.ts
Normal file
7
apps/api/src/modules/users/posts.module.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { PostsController } from './controllers/posts/posts.controller';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
controllers: [PostsController],
|
||||||
|
})
|
||||||
|
export class PostsModule {}
|
||||||
16
apps/web-app/Dockerfile.dev
Normal file
16
apps/web-app/Dockerfile.dev
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
FROM node:20-bookworm-slim
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
RUN corepack enable
|
||||||
|
|
||||||
|
# Dependencies (from workspace root)
|
||||||
|
COPY package.json pnpm-lock.yaml ./
|
||||||
|
RUN pnpm install
|
||||||
|
|
||||||
|
# Monorepo structure
|
||||||
|
COPY nx.json tsconfig.base.json ./
|
||||||
|
COPY apps/web-app ./apps/web-app
|
||||||
|
COPY libs ./libs
|
||||||
|
|
||||||
|
ENV HOSTNAME=0.0.0.0
|
||||||
|
CMD ["pnpm", "nx", "serve", "web-app"]
|
||||||
@@ -514,6 +514,7 @@ import { CommonModule } from '@angular/common';
|
|||||||
<h1>
|
<h1>
|
||||||
<span> Hello there, </span>
|
<span> Hello there, </span>
|
||||||
Welcome web-app 👋
|
Welcome web-app 👋
|
||||||
|
<span> HMR is working! </span>
|
||||||
</h1>
|
</h1>
|
||||||
</div>
|
</div>
|
||||||
<!-- HERO -->
|
<!-- HERO -->
|
||||||
|
|||||||
63
docker-compose.yml
Normal file
63
docker-compose.yml
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
services:
|
||||||
|
db:
|
||||||
|
image: postgres:18-alpine
|
||||||
|
environment:
|
||||||
|
POSTGRES_USER: webapp
|
||||||
|
POSTGRES_PASSWORD: webpass
|
||||||
|
POSTGRES_DB: webappdb
|
||||||
|
PGDATA: /var/lib/postgresql/data
|
||||||
|
ports:
|
||||||
|
- "5432:5432"
|
||||||
|
volumes:
|
||||||
|
- webapp_pgdata:/var/lib/postgresql/data
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "pg_isready -U webapp -d webappdb"]
|
||||||
|
interval: 10s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 5
|
||||||
|
|
||||||
|
api:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: ./apps/api/Dockerfile.dev
|
||||||
|
command: sh -c "pnpm install && pnpm prisma generate && pnpm prisma migrate deploy && pnpm nx serve api"
|
||||||
|
ports:
|
||||||
|
- "3000:3000"
|
||||||
|
environment:
|
||||||
|
- NODE_ENV=development
|
||||||
|
- DATABASE_URL=postgresql://webapp:webpass@db:5432/webappdb
|
||||||
|
- NX_DAEMON=false
|
||||||
|
- NX_WORKSPACE_DATA_DIRECTORY=/tmp/nx-workspace-data-api
|
||||||
|
- NX_CACHE_DIRECTORY=/tmp/nx-cache-api
|
||||||
|
stop_grace_period: 5s
|
||||||
|
depends_on:
|
||||||
|
db:
|
||||||
|
condition: service_healthy
|
||||||
|
volumes:
|
||||||
|
- .:/app
|
||||||
|
- api_node_modules:/app/node_modules
|
||||||
|
|
||||||
|
web:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: ./apps/web-app/Dockerfile.dev
|
||||||
|
command: sh -c "pnpm install && pnpm nx serve web-app --host 0.0.0.0 --port 4200"
|
||||||
|
ports:
|
||||||
|
- "4200:4200"
|
||||||
|
environment:
|
||||||
|
- NODE_ENV=development
|
||||||
|
- NX_DAEMON=false
|
||||||
|
- NX_WORKSPACE_DATA_DIRECTORY=/tmp/nx-workspace-data-web
|
||||||
|
- NX_CACHE_DIRECTORY=/tmp/nx-cache-web
|
||||||
|
stop_grace_period: 5s
|
||||||
|
volumes:
|
||||||
|
- .:/app
|
||||||
|
- web_node_modules:/app/node_modules
|
||||||
|
depends_on:
|
||||||
|
api:
|
||||||
|
condition: service_started
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
webapp_pgdata:
|
||||||
|
api_node_modules:
|
||||||
|
web_node_modules:
|
||||||
15
prisma/migrations/20260326110513_init/migration.sql
Normal file
15
prisma/migrations/20260326110513_init/migration.sql
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
-- CreateEnum
|
||||||
|
CREATE TYPE "PostStatus" AS ENUM ('DRAFT', 'PUBLISHED', 'ARCHIVED');
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE "posts" (
|
||||||
|
"id" TEXT NOT NULL,
|
||||||
|
"title" TEXT NOT NULL,
|
||||||
|
"content" TEXT,
|
||||||
|
"status" "PostStatus" NOT NULL DEFAULT 'DRAFT',
|
||||||
|
"authorName" TEXT NOT NULL,
|
||||||
|
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||||
|
|
||||||
|
CONSTRAINT "posts_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
3
prisma/migrations/migration_lock.toml
Normal file
3
prisma/migrations/migration_lock.toml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Please do not edit this file manually
|
||||||
|
# It should be added in your version-control system (e.g., Git)
|
||||||
|
provider = "postgresql"
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
// This is your Prisma schema file,
|
// This is your Prisma schema file,
|
||||||
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
||||||
|
|
||||||
// Get a free hosted Postgres database in seconds: `npx create-db`
|
|
||||||
|
|
||||||
generator client {
|
generator client {
|
||||||
provider = "prisma-client"
|
provider = "prisma-client"
|
||||||
output = "../libs/prisma-generated/src/lib/generated"
|
output = "../libs/prisma-generated/src/lib/generated"
|
||||||
|
|||||||
5
prisma/seed.sql
Normal file
5
prisma/seed.sql
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
INSERT INTO "posts" ("id","title","content","status","authorName","createdAt","updatedAt")
|
||||||
|
VALUES
|
||||||
|
('post_1','Hello Prisma','First seeded post','DRAFT','Alice',NOW(),NOW()),
|
||||||
|
('post_2','Published post','Seeded and published','PUBLISHED','Bob',NOW(),NOW())
|
||||||
|
ON CONFLICT ("id") DO NOTHING;
|
||||||
Reference in New Issue
Block a user