Skip to content

Commit

Permalink
fixed docker
Browse files Browse the repository at this point in the history
  • Loading branch information
ClaudioMartinH committed Sep 19, 2024
1 parent 3a9b110 commit 0e5a095
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 129 deletions.
20 changes: 10 additions & 10 deletions client/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
server: {
proxy: {
'/api': {
target: 'http://localhost:3000',
changeOrigin: true,
},
},
plugins: [react()],
server: {
proxy: {
"/api": {
target: "http://backend:3000",
changeOrigin: true,
},
},
},
});
2 changes: 1 addition & 1 deletion client/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default defineConfig({
open: true,
proxy: {
"/api": {
target: "http://localhost:3000",
target: "http://backend:3000",
changeOrigin: true,
},
},
Expand Down
7 changes: 4 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ services:
- node_modules:/usr/src/app/node_modules
depends_on:
- backend
environment:
- VITE_API_URL=http://backend:3000

backend:
build:
Expand All @@ -20,9 +22,8 @@ services:
volumes:
- ./server:/usr/src/app
- ./data:/usr/src/app/data
environment:
- DATABASE_URL=/usr/src/app/data/dev.db

- /usr/src/app/node_modules

volumes:
node_modules:
data:
Expand Down
3 changes: 2 additions & 1 deletion server/.dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
dist
17 changes: 15 additions & 2 deletions server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,25 @@ FROM node:20

WORKDIR /usr/src/app

COPY . .
ENV DATABASE_URL="file:./dev.db"

ENV JWT_SECRET=2c146a3da80f85866a3083e51e631c207fb45456ad86569992f1445a4043f788

COPY package*.json ./

RUN npm install

COPY prisma ./prisma/

RUN npx prisma generate

COPY . .

RUN npm run build
RUN ls -la dist
RUN ls -R /usr/src/app
RUN cat dist/index.js || echo "index.js no existe"

EXPOSE 3000

CMD ["npm", "run", "start"]
CMD ["npm", "start"]
6 changes: 3 additions & 3 deletions server/package-lock.json

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

8 changes: 4 additions & 4 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"name": "6-claudio-martin-andrea-rethy",
"version": "1.0.0",
"description": "",
"main": "./dist/src/index.js",
"main": "./dist/index.js",
"type": "module",
"scripts": {
"dev": "nodemon ./dist/src/index.js",
"dev": "nodemon dist/index.js",
"test": "vitest",
"build": "tsc",
"start": "node ./dist/src/index.js"
"start": "node dist/index.js"
},
"keywords": [],
"author": "ClaudioMartinH & Andrea Rethy",
Expand All @@ -31,4 +31,4 @@
"jsonwebtoken": "^9.0.2",
"prisma": "^5.19.1"
}
}
}
Binary file modified server/prisma/dev.db
Binary file not shown.
70 changes: 0 additions & 70 deletions server/prisma/seed.ts

This file was deleted.

7 changes: 2 additions & 5 deletions server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@ import loginRoutes from "./routes/login.routes.js";
import authMiddlewareJWT from "./middleware/authMiddleware.js";
import dotenv from "dotenv";
import cors from "cors";
// import { PlayerController } from "./infrastructure/controllers/playerController.js";

// const playerController = new PlayerController();
dotenv.config();
const app = express();
app.use(
cors({
origin: "http://localhost:5173",
methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
allowedHeaders: ["Content-Type", "Authorization"],
credentials: true
credentials: true,
})
);

Expand All @@ -26,11 +24,10 @@ const PORT = process.env.PORT || 3000;
app.use(express.json());

app.use("/api", loginRoutes);
// app.post("/api/players", playerController.createPlayer);
app.use("/api", authMiddlewareJWT, playersRoutes);
app.use("/api", authMiddlewareJWT, gamesRoutes);
app.use("/api", authMiddlewareJWT, rankingsRoutes);

app.listen(PORT, () => {
app.listen(Number(PORT), "0.0.0.0", () => {
console.log(`Server listening on localhost:${PORT}`);
});
36 changes: 6 additions & 30 deletions server/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
{
"compilerOptions": {
"types": [
"@types/node",
"@prisma/client"
],
"target": "ES6",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"strict": true,
"outDir": "./dist",
"rootDir": "./src",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"removeComments": true,
Expand All @@ -28,33 +33,4 @@
"exclude": [
"node_modules"
]
}
// {
// "compilerOptions": {
// "target": "ES6",
// "module": "ESNext",
// "strict": true,
// "outDir": "./dist",
// "esModuleInterop": true,
// "forceConsistentCasingInFileNames": true,
// "removeComments": true,
// "skipLibCheck": true,
// "allowSyntheticDefaultImports": true,
// "noEmitHelpers": true,
// "noImplicitReturns": true,
// "noUnusedLocals": true,
// "noUnusedParameters": true,
// "baseUrl": ".",
// "paths": {
// "@prisma/client": [
// "./node_modules/@prisma/client"
// ]
// }
// },
// "include": [
// "./src/**/*.ts"
// ],
// "exclude": [
// "node_modules"
// ]
// }
}

0 comments on commit 0e5a095

Please sign in to comment.