Skip to content

Commit

Permalink
set initial server files/config
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobdcastro committed Jun 11, 2024
1 parent b9aa9fa commit a439cca
Show file tree
Hide file tree
Showing 12 changed files with 3,500 additions and 2,705 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20.12.2
2 changes: 2 additions & 0 deletions apps/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"lint": "next lint"
},
"dependencies": {
"@repo/eslint-config": "*",
"@repo/typescript-config": "*",
"react": "^18",
"react-dom": "^18",
"next": "14.2.3"
Expand Down
5 changes: 1 addition & 4 deletions apps/client/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
{
"extends": "@repo/typescript-config/nextjs.json",
"compilerOptions": {
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
Expand Down
37 changes: 37 additions & 0 deletions apps/server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM node:alpine AS builder
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
RUN apk update

WORKDIR /app
RUN yarn global add turbo
COPY . .
RUN turbo prune --scope=api --docker

# Add lockfile and package.json's of isolated subworkspace
FROM node:alpine AS installer
RUN apk add --no-cache libc6-compat
RUN apk update
WORKDIR /app

# First install dependencies (as they change less often)
COPY .gitignore .gitignore
COPY --from=builder /app/out/json/ .
COPY --from=builder /app/out/yarn.lock ./yarn.lock
RUN yarn install

# Build the project and its dependencies
COPY --from=builder /app/out/full/ .
COPY turbo.json turbo.json
RUN yarn turbo run build --filter=api...

FROM node:alpine AS runner
WORKDIR /app

# Don't run production as root
RUN addgroup --system --gid 1001 expressjs
RUN adduser --system --uid 1001 expressjs
USER expressjs
COPY --from=installer /app .

CMD node apps/api/dist/index.js
5 changes: 5 additions & 0 deletions apps/server/nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"watch": ["src"],
"ext": "ts",
"exec": "concurrently \"npx tsc --watch\" \"ts-node src/index.ts\""
}
28 changes: 28 additions & 0 deletions apps/server/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "server",
"version": "0.1.0",
"main": "index.js",
"scripts": {
"build": "npx tsc",
"start": "node dist/index.js",
"dev": "nodemon src/index.ts",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Jacob D. Castro",
"license": "MIT",
"description": "",
"dependencies": {
"@repo/eslint-config": "*",
"@repo/typescript-config": "*",
"@types/express": "^4.17.21",
"@types/node": "^20",
"dotenv": "^16.4.5",
"express": "^4.19.2",
"typescript": "^5.4.5"
},
"devDependencies": {
"concurrently": "^8.2.2",
"nodemon": "^3.1.3",
"ts-node": "^10.9.2"
}
}
14 changes: 14 additions & 0 deletions apps/server/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import express, { Express, Request, Response } from "express";
import dotenv from "dotenv";
dotenv.config();

const app: Express = express();
const port = process.env.PORT || 3000;

app.get("/", (req: Request, res: Response) => {
res.send("Express + TypeScript Server");
});

app.listen(port, () => {
console.log(`[server]: Server is running at http://localhost:${port}`);
});
6 changes: 6 additions & 0 deletions apps/server/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "@repo/typescript-config/node.json",
"compilerOptions": {
"outDir": "./dist"
}
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
"scripts": {
"build": "turbo build",
"build-client": "turbo build --filter=client",
"build-server": "turbo build --filter=server",
"dev": "turbo dev",
"dev-client": "turbo dev --filter=client",
"dev-server": "turbo dev --filter=server",
"lint": "turbo lint",
"lint-client": "turbo lint --filter=client",
"lint-server": "turbo lint --filter=server",
"format": "prettier --write \"**/*.{ts,tsx,md}\""
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript-config/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"declaration": true,
"declarationMap": true,
"esModuleInterop": true,
"incremental": false,
"incremental": true,
"isolatedModules": true,
"lib": ["es2022", "DOM", "DOM.Iterable"],
"module": "NodeNext",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "React Library",
"display": "Node Server",
"extends": "./base.json",
"compilerOptions": {
"jsx": "react-jsx"
}
}
Loading

0 comments on commit a439cca

Please sign in to comment.