Skip to content

Commit bde1ed0

Browse files
committed
Fix frontend and backend issue
1 parent 2379d10 commit bde1ed0

File tree

22 files changed

+235
-380
lines changed

22 files changed

+235
-380
lines changed

.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ CLIENT_API_BASE_URL=http://127.0.0.1:6868/api
1414

1515
REACT_LOCAL_PORT=8080
1616
REACT_DOCKER_PORT=8080
17+
18+
#Frontend
19+
VITE_API_URL=http://localhost:8888/
20+

backend/Dockerfile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@ FROM node:18
22

33
WORKDIR /backend
44

5+
RUN echo "Set working directory for backend === $(pwd)"
6+
57
COPY package.json .
68
COPY package*.json ./
79
COPY tsconfig*.json ./
810

11+
RUN echo "Install deps within === $(pwd)"
12+
913
RUN npm install -g pnpm
1014
RUN pnpm install
1115

@@ -15,17 +19,18 @@ COPY ./waitForIt.sh ./
1519
COPY ./migratePrisma.sh ./
1620

1721
# run prisma
22+
RUN echo "Running prisma === $(pwd)"
1823
RUN npx prisma generate
1924
RUN chmod +x waitForIt.sh
2025
RUN chmod +x migratePrisma.sh
2126

22-
2327
# RUN pnpm run build
2428
EXPOSE $NODE_DOCKER_PORT
2529

26-
2730
CMD ["./waitForIt.sh", "db:3306", "--", "./migratePrisma.sh"]
2831

32+
RUN echo "Running nginx server === $(pwd)"
33+
2934
CMD ["npx","prisma", "migrate", "dev"]
3035
CMD ["pnpm", "run", "start"]
3136

backend/prisma/old-migs/20231011220759_init/migration.sql

Lines changed: 0 additions & 13 deletions
This file was deleted.

backend/prisma/old-migs/20231015213738_relations/migration.sql

Lines changed: 0 additions & 49 deletions
This file was deleted.

backend/prisma/old-migs/20240919030844_cafe_emp/migration.sql

Lines changed: 0 additions & 31 deletions
This file was deleted.

backend/prisma/old-migs/20240919031931_again/migration.sql

Lines changed: 0 additions & 2 deletions
This file was deleted.

backend/prisma/old-migs/20240919033817_update_cafe_employees/migration.sql

Lines changed: 0 additions & 14 deletions
This file was deleted.

backend/prisma/old-migs/20240919034312_clean_up_schema/migration.sql

Lines changed: 0 additions & 36 deletions
This file was deleted.

backend/src/app.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import { Injectable } from '@nestjs/common';
33
@Injectable()
44
export class AppService {
55
getHello(): string {
6-
return 'Café Page!';
6+
return 'Café Page API!';
77
}
88
}

backend/src/cafes/cafes.controller.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
Patch,
77
Param,
88
Delete,
9+
Header
910
} from '@nestjs/common';
1011
import { Prisma } from '@prisma/client';
1112
import { CafesService } from './cafes.service';
@@ -20,11 +21,13 @@ export class CafesController {
2021
}
2122

2223
@Get()
24+
@Header('Content-Type', 'application/json')
2325
findAll() {
2426
return this.cafesService.findAll();
2527
}
2628

2729
@Get(':id')
30+
@Header('Content-Type', 'application/json')
2831
findOne(@Param('id') id: string) {
2932
return this.cafesService.findOne(+id);
3033
}

backend/src/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { NestFactory } from '@nestjs/core';
22
import { AppModule } from './app.module';
3+
import { CorsOptions } from '@nestjs/common/interfaces/external/cors-options.interface';
34

45
async function bootstrap() {
56
const app = await NestFactory.create(AppModule);
@@ -10,8 +11,7 @@ async function bootstrap() {
1011
preflightContinue: false,
1112
optionsSuccessStatus: 204,
1213
credentials: true,
13-
};
14-
14+
} as CorsOptions;
1515
app.enableCors(options);
1616
await app.listen(port || 8888);
1717
}

frontend/.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# NOTE: Change this according to your prod settigns
2+
VITE_API_URL=http://localhost:8888/

frontend/.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
.idea
44
.DS_Store
55

6-
76
logs
87
*.log
98
npm-debug.log*
@@ -17,5 +16,7 @@ dist
1716
dist-ssr
1817
*.local
1918

20-
.env
2119
docs
20+
21+
# NOTE: In real world we need to add this file to get ignore when pushing to the repo
22+
# .env

frontend/Dockerfile

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ FROM node:18-alpine AS vite-app
22
#ENV NODE_ENV production
33
WORKDIR /frontend
44

5-
65
COPY . .
76
#COPY package*.json ./
87
#COPY tsconfig*.json ./
@@ -14,7 +13,7 @@ RUN npm install -g pnpm
1413
RUN pnpm install
1514
COPY . .
1615

17-
16+
RUN echo "Running build frontend in === $(pwd)"
1817
RUN pnpm run build
1918

2019
FROM nginx:alpine
@@ -24,19 +23,18 @@ FROM nginx:alpine
2423
#WORKDIR /frontend/dist
2524

2625
WORKDIR /usr/share/nginx/
26+
RUN echo "Set working directory for nginx in === $(pwd)"
2727
RUN rm -rf html
2828
RUN mkdir html
2929
WORKDIR /
3030

31-
#RUN rm -rf *
32-
31+
RUN echo "Set working directory within nginx html to dis in === $(pwd)"
3332

3433
#COPY --from=builder /frontend/dist .
3534
#COPY --from=builder /frontend/dist /etc/nginx/html
3635
COPY nginx/nginx.conf /etc/nginx
37-
COPY --from=vite-app /frontend/dist /usr/share/nginx/html
36+
COPY --from=vite-app /frontend/dist /usr/share/nginx/html
3837
#STOPSIGNAL SIGTERM
3938
#EXPOSE 3000
4039

4140
ENTRYPOINT ["nginx", "-g", "daemon off;"]
42-

frontend/src/api/clients/axios-client.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,19 @@ import axios, { AxiosError } from 'axios';
33
const axiosClient = axios.create({
44
baseURL: import.meta.env.VITE_API_URL,
55
headers: {
6-
'Content-Type': 'application/json',
76
'Cache-Control': 'no-cache',
87
'Access-Control-Allow-Origin': '*',
8+
'Content-Type': 'application/json;charset=UTF-8',
99
'Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE,PATCH,OPTIONS',
10+
Accept: 'application/json'
1011
},
11-
withCredentials: false,
1212
});
1313

1414
axiosClient.interceptors.response.use(
1515
function (response) {
1616
return response.data;
1717
},
1818
function (error: AxiosError) {
19-
if (error.response?.status === 401) {
20-
localStorage.removeItem('token');
21-
}
2219
return Promise.reject(error);
2320
}
2421
);

frontend/src/layouts/Header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const Header: React.FC<HeaderProps> = ({ darkMode, setDarkMode }) => {
1212
<AppBar position="fixed" sx={{ zIndex: (theme) => theme.zIndex.drawer + 1 }}>
1313
<Toolbar>
1414
<Typography variant="h6" noWrap component="div" sx={{ flexGrow: 1 }}>
15-
Cafe Management
15+
Cafe Employee
1616
</Typography>
1717
<IconButton color="inherit" onClick={setDarkMode}>
1818
{darkMode ? <Brightness7Icon /> : <Brightness4Icon />}

frontend/src/layouts/Sidebar.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ const Sidebar = () => {
3434
}}>
3535
<ListItem disablePadding>
3636
<ListItemButton
37-
selected={isActive}
3837
sx={{
3938
'&.Mui-selected': {
4039
backgroundColor: theme.palette.action.selected,
@@ -49,12 +48,7 @@ const Sidebar = () => {
4948
}}>
5049
{route.icon}
5150
</ListItemIcon>
52-
<ListItemText
53-
primary={route.label}
54-
sx={{
55-
color: isActive ? theme.palette.primary.main : 'inherit',
56-
}}
57-
/>
51+
<ListItemText primary={route.label} />
5852
</ListItemButton>
5953
</ListItem>
6054
</Link>

0 commit comments

Comments
 (0)