Finalize template

This commit is contained in:
Toni Koskinen
2026-03-26 13:45:33 +02:00
parent 1786acc75c
commit 4517620d9e
12 changed files with 158 additions and 3 deletions

4
.gitignore vendored
View File

@@ -36,6 +36,10 @@ npm-debug.log
yarn-error.log
testem.log
/typings
pnpm-debug.log
pnpm-error.log
package-lock.json
.pnpm-store/
# System Files
.DS_Store

17
apps/api/Dockerfile.dev Normal file
View 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"]

View File

@@ -1,9 +1,10 @@
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { PostsModule } from '../modules/users/posts.module';
@Module({
imports: [],
imports: [PostsModule],
controllers: [AppController],
providers: [AppService],
})

View File

@@ -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;
}
}

View File

@@ -0,0 +1,7 @@
import { Module } from '@nestjs/common';
import { PostsController } from './controllers/posts/posts.controller';
@Module({
controllers: [PostsController],
})
export class PostsModule {}

View 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"]

View File

@@ -514,6 +514,7 @@ import { CommonModule } from '@angular/common';
<h1>
<span> Hello there, </span>
Welcome web-app 👋
<span> HMR is working! </span>
</h1>
</div>
<!-- HERO -->

63
docker-compose.yml Normal file
View 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:

View 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")
);

View 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"

View File

@@ -1,8 +1,6 @@
// This is your Prisma schema file,
// 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 {
provider = "prisma-client"
output = "../libs/prisma-generated/src/lib/generated"

5
prisma/seed.sql Normal file
View 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;