Skip to content

Commit c3398bc

Browse files
authored
Merge branch 'ISUCT:master' into master
2 parents 895e231 + 645f508 commit c3398bc

35 files changed

Lines changed: 2727 additions & 1889 deletions

onlineshop/.env

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ NODE_ENV=development
44
SERVER_HOST=localhost
55
SERVER_PORT=3000
66
SERVER_WEB_HOST=localhost
7-
SERVER_WEB_PORT=4000
7+
SERVER_WEB_PORT=4000
8+
DB_USER=postgres
9+
DB_PASSWORD=postgres
10+
DB_PORT=5432
11+
DB_NAME=sample

onlineshop/docker-compose.yaml

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ services:
99
- POSTGRES_PASSWORD=${DB_PASSWORD}
1010
- POSTGRES_DB=${DB_NAME}
1111
volumes:
12-
- ./pgdata:/var/lib/postgresql/data
12+
- sample:/var/lib/postgresql/data
1313
ports:
1414
- "${DB_PORT}:5432"
1515

@@ -20,5 +20,33 @@ services:
2020
- "8000:8080"
2121
links:
2222
- db
23+
server:
24+
env_file: .env
25+
build:
26+
context: ./source/server/
27+
dockerfile: ./Dockerfile
28+
image: isuct/web-app:server
29+
environment:
30+
- SOME_VAR=my_var
31+
ports:
32+
- 3000:3000
33+
depends_on:
34+
- db
2335

36+
client:
37+
env_file: .env
38+
build:
39+
context: ./source/client/
40+
dockerfile: ./Dockerfile
41+
image: isuct/web-app:client
42+
environment:
43+
- SOME_VAR=another_var
44+
volumes:
45+
- ./source/client/nginx.conf:/etc/nginx/nginx.conf
46+
ports:
47+
- 8082:80
48+
depends_on:
49+
- server
2450

51+
volumes:
52+
sample:
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
**/README.md
2+
**/node_modules/
3+
**/test/
4+
.git
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM node:20.19.1-alpine as build
2+
WORKDIR /app
3+
COPY ./package.json ./
4+
COPY ./yarn.lock ./
5+
RUN yarn
6+
COPY ./ ./
7+
# ENV NODE_ENV="production"
8+
RUN yarn run build
9+
# ------
10+
FROM nginx:alpine
11+
12+
COPY --from=build /app/dist/ /usr/share/nginx/html
13+
COPY ./nginx.conf /etc/nginx/nginx.conf
14+
15+
CMD ["nginx", "-g", "daemon off;"]
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
worker_processes 1;
2+
3+
events {
4+
worker_connections 1024;
5+
}
6+
7+
8+
http {
9+
include mime.types;
10+
default_type application/octet-stream;
11+
12+
log_format compression '$remote_addr - $remote_user [$time_local] '
13+
'"$request" $status $upstream_addr '
14+
'"$http_referer" "$http_user_agent" "$gzip_ratio"';
15+
16+
sendfile on;
17+
keepalive_timeout 165;
18+
gzip on;
19+
20+
21+
server {
22+
listen * default_server;
23+
# server_name it.isuct.ru oldit.isuct.ru;
24+
25+
client_max_body_size 25m;
26+
27+
location /api/ {
28+
proxy_pass http://server:3000/api/;
29+
proxy_http_version 1.1;
30+
proxy_set_header Upgrade $http_upgrade;
31+
proxy_set_header Connection 'upgrade';
32+
proxy_set_header Host $host;
33+
proxy_cache_bypass $http_upgrade;
34+
}
35+
36+
location / {
37+
root /usr/share/nginx/html;
38+
index index.html index.htm;
39+
try_files $uri /index.html;
40+
}
41+
#error_page 404 /404.html;
42+
43+
# redirect server error pages to the static page /50x.html
44+
#
45+
error_page 500 502 503 504 /50x.html;
46+
location = /50x.html {
47+
root html;
48+
}
49+
}
50+
}
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
import React from 'react';
22

33
import './App.css';
4+
import First from './components/first';
5+
import DogList from './components/dogList';
46

57
const App: React.FC = () => (
6-
<div className="App">
7-
<header className="App-header">
8-
<p>
9-
Edit <code>src/App.tsx</code> and save to reload.
10-
</p>
11-
<a className="App-link" href="https://reactjs.org" target="_blank" rel="noopener noreferrer">
12-
Learn React
13-
</a>
14-
</header>
15-
</div>
8+
<>
9+
<h1>Hello World!</h1>
10+
<h2>Hello</h2>
11+
<First />
12+
<DogList />
13+
</>
1614
);
1715

1816
export default App;
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import React from 'react'
2+
import { Dog } from './dogList'
3+
import Button from '@mui/material/Button';
4+
import TextField from '@mui/material/TextField';
5+
6+
7+
interface IProps {
8+
dog: Dog
9+
}
10+
11+
const updateDog = async (dog: Dog) => {
12+
let method = "POST";
13+
let url = "/api/dogs/";
14+
if (dog.id !== 0) {
15+
method = "PUT";
16+
url += `${dog.id}`;
17+
}
18+
return await fetch(url,{
19+
method: method, // *GET, POST, PUT, DELETE, etc.
20+
headers: {
21+
"Content-Type": "application/json",
22+
// 'Content-Type': 'application/x-www-form-urlencoded',
23+
},
24+
body: JSON.stringify(dog), // body data type must match "Content-Type" header
25+
});
26+
}
27+
28+
export default function DogItem(props: IProps) {
29+
const [name, setName] = React.useState<string>(props.dog.name);
30+
31+
const onChange = (event: React.ChangeEvent<HTMLInputElement>) => {
32+
setName(event.target.value)
33+
}
34+
return (
35+
<div>
36+
<h1>Dog:</h1>
37+
<TextField
38+
id="standard-basic"
39+
label="Name"
40+
variant="standard"
41+
value={name}
42+
onChange={onChange}
43+
/>
44+
<h4>Age: {props.dog.age}</h4>
45+
<Button variant="contained" color="success" onClick={() => updateDog({...props.dog, name: name})}>
46+
Сохранить
47+
</Button>
48+
</div>
49+
)
50+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import React from 'react'
2+
import DogItem from './dogItem';
3+
import { create } from 'domain';
4+
import Button from '@mui/material/Button';
5+
6+
export interface Dog {
7+
id: number,
8+
name: string,
9+
age: number
10+
}
11+
12+
const getDogs = async (): Promise<Dog[]> => {
13+
const data = await fetch('/api/dogs')
14+
return await data.json();
15+
// const dogs = [{ name: "Bob", age: 1 }, { name: "Alice", age: 2 }, { name: "Charlie", age: 3 }]
16+
// return new Promise((resolve) => setTimeout(() => resolve(dogs), 5000));
17+
}
18+
19+
20+
export default function DogList() {
21+
const [dogs, setDogs] = React.useState<Dog[]>([]);
22+
23+
const createDog = async () => {
24+
setDogs([...dogs, { id: 0, name: "", age: 0 }]);
25+
}
26+
27+
React.useEffect(() => {
28+
let isMounted = true;
29+
const fetchDogs = async () => {
30+
console.log("fetching");
31+
const dogs = await getDogs();
32+
if (!isMounted) return;
33+
setDogs(dogs);
34+
}
35+
fetchDogs();
36+
return () => {
37+
isMounted = false;
38+
}
39+
}, []);
40+
return (
41+
<div>
42+
<h1>Dog List</h1>
43+
<Button variant="contained" color="success" onClick={createDog}>
44+
Добавить
45+
</Button>
46+
{
47+
dogs.map((dog, index) => <DogItem dog={dog} key={dog.id} />)
48+
}
49+
</div>
50+
)
51+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react'
2+
import Button from '@mui/material/Button';
3+
4+
export default function First() {
5+
const [count, setCount] = React.useState(0);
6+
7+
const handleClick = () => {
8+
setCount(count + 1);
9+
console.log(`Clicked ${count}`)
10+
};
11+
return (
12+
<div>
13+
<h2>Click count: {count}</h2>
14+
<Button variant="contained" onClick={handleClick}>Contained</Button>
15+
</div>
16+
)
17+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
**/README.md
2+
**/node_modules/
3+
**/test/
4+
.git

0 commit comments

Comments
 (0)