инициализировал проект

This commit is contained in:
dyakonovr 2024-03-24 19:49:46 +04:00
parent 61bfbd0275
commit 6bae91ec48
36 changed files with 7892 additions and 14 deletions

15
.gitignore vendored
View File

@ -1,14 +1 @@
# ---> VisualStudioCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets
# Local History for Visual Studio Code
.history/
# Built Visual Studio Code Extensions
*.vsix
node_modules

2
client/.env Normal file
View File

@ -0,0 +1,2 @@
VITE_SIMPLE_REST_URL=http://my.api.url/

20
client/.eslintrc.js Normal file
View File

@ -0,0 +1,20 @@
module.exports = {
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:react/jsx-runtime",
"plugin:react-hooks/recommended",
"prettier"
],
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"env": {
"browser": true,
"es2021": true
},
"settings": {
"react": {
"version": "detect"
}
}
}

24
client/.gitignore vendored Normal file
View File

@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

125
client/index.html Normal file
View File

@ -0,0 +1,125 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="minimum-scale=1, initial-scale=1, width=device-width, shrink-to-fit=no"
/>
<meta name="theme-color" content="#000000" />
<link rel="manifest" href="./manifest.json" />
<link rel="shortcut icon" href="./favicon.ico" />
<title>client</title>
<style>
body {
margin: 0;
padding: 0;
font-family: sans-serif;
}
.loader-container {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background-color: #fafafa;
}
/* CSS Spinner from https://projects.lukehaas.me/css-loaders/ */
.loader,
.loader:before,
.loader:after {
border-radius: 50%;
}
.loader {
color: #283593;
font-size: 11px;
text-indent: -99999em;
margin: 55px auto;
position: relative;
width: 10em;
height: 10em;
box-shadow: inset 0 0 0 1em;
-webkit-transform: translateZ(0);
-ms-transform: translateZ(0);
transform: translateZ(0);
}
.loader:before,
.loader:after {
position: absolute;
content: '';
}
.loader:before {
width: 5.2em;
height: 10.2em;
background: #fafafa;
border-radius: 10.2em 0 0 10.2em;
top: -0.1em;
left: -0.1em;
-webkit-transform-origin: 5.2em 5.1em;
transform-origin: 5.2em 5.1em;
-webkit-animation: load2 2s infinite ease 1.5s;
animation: load2 2s infinite ease 1.5s;
}
.loader:after {
width: 5.2em;
height: 10.2em;
background: #fafafa;
border-radius: 0 10.2em 10.2em 0;
top: -0.1em;
left: 5.1em;
-webkit-transform-origin: 0px 5.1em;
transform-origin: 0px 5.1em;
-webkit-animation: load2 2s infinite ease;
animation: load2 2s infinite ease;
}
@-webkit-keyframes load2 {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
@keyframes load2 {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
</style>
<link rel="preconnect" href="https://fonts.gstatic.com" />
<link
href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap"
rel="stylesheet"
/>
</head>
<body>
<noscript> You need to enable JavaScript to run this app. </noscript>
<div id="root">
<div class="loader-container">
<div class="loader">Loading...</div>
</div>
</div>
</body>
<script type="module" src="/src/index.tsx"></script>
</html>

5606
client/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

33
client/package.json Normal file
View File

@ -0,0 +1,33 @@
{
"name": "client",
"private": true,
"scripts": {
"dev": "vite",
"build": "vite build",
"serve": "vite preview",
"type-check": "tsc --noEmit",
"lint": "eslint --fix --ext .js,.jsx,.ts,.tsx ./src",
"format": "prettier --write ./src"
},
"dependencies": {
"ra-data-simple-rest": "^4.16.0",
"react": "^18.2.0",
"react-admin": "^4.16.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@typescript-eslint/parser": "^5.60.1",
"@typescript-eslint/eslint-plugin": "^5.60.1",
"@types/node": "^18.16.1",
"@types/react": "^18.0.22",
"@types/react-dom": "^18.0.7",
"@vitejs/plugin-react": "^4.0.1",
"eslint": "^8.43.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
"prettier": "^2.8.8",
"typescript": "^5.1.6",
"vite": "^4.3.9"
}
}

View File

@ -0,0 +1 @@
module.exports = {}

8
client/src/App.tsx Normal file
View File

@ -0,0 +1,8 @@
import { Admin } from "react-admin";
import { dataProvider } from "./dataProvider";
function App() {
return (<Admin dataProvider={dataProvider}></Admin>);
}
export default App;

View File

@ -0,0 +1,5 @@
import simpleRestProvider from "ra-data-simple-rest";
export const dataProvider = simpleRestProvider(
import.meta.env.VITE_SIMPLE_REST_URL
);

9
client/src/index.tsx Normal file
View File

@ -0,0 +1,9 @@
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";
ReactDOM.createRoot(document.getElementById("root")!).render(
<React.StrictMode>
<App />
</React.StrictMode>
);

1
client/src/vite-env.d.ts vendored Normal file
View File

@ -0,0 +1 @@
/// <reference types="vite/client" />

26
client/tsconfig.json Normal file
View File

@ -0,0 +1,26 @@
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": [
"src"
]
}

14
client/vite.config.ts Normal file
View File

@ -0,0 +1,14 @@
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
define: {
'process.env': process.env,
},
server: {
host: true,
},
base: './',
});

6
server/.env Normal file
View File

@ -0,0 +1,6 @@
PORT=5000
DB_NAME=react_qpick_shop
DB_USER=postgres
DB_PASSWORD=postgres
DB_HOST=localhost
DB_PORT=5433

View File

View File

View File

View File

View File

15
server/db.js Normal file
View File

@ -0,0 +1,15 @@
import dotenv from "dotenv";
import { Sequelize } from "sequelize";
dotenv.config();
export const sequelize = new Sequelize(
process.env.DB_NAME,
process.env.DB_USER,
process.env.DB_PASSWORD,
{
dialect: "postgres",
host: process.env.DB_HOST,
port: process.env.DB_PORT
}
);

View File

@ -0,0 +1,19 @@
export class ApiErrorHandler extends Error {
constructor(status, message) {
super();
this.status = status;
this.message = message;
}
static notFound(message) {
return new ApiErrorHandler(404, message);
}
static internal(message) {
return new ApiErrorHandler(500, `Ошибка сервера: ${message}`);
}
static forbidden(message) {
return new ApiErrorHandler(403, message);
}
}

View File

@ -0,0 +1,7 @@
export function generateSlug(str) {
return str
.toLowerCase() // Преобразование в нижний регистр
.replace(/[^a-zA-Z0-9]/g, '-') // Замена спецсимволов на дефисы
.replace(/-{2,}/g, '-') // Удаление повторяющихся дефисов
.replace(/^-+|-+$/g, ''); // Удаление дефисов в начале и конце строки
}

28
server/index.js Normal file
View File

@ -0,0 +1,28 @@
import express from "express";
import { sequelize } from './db.js';
import cors from "cors";
import { router } from "./routes/routes.js";
import { ErrorHandlingMiddleware } from "./middleware/error-handling.middleware.js";
const port = 5000;
const app = express();
app.use(cors());
app.use(express.json());
app.use("/api/", router);
app.use(ErrorHandlingMiddleware);
const start = async () => {
try {
await sequelize.authenticate();
await sequelize.sync();
app.listen(port, () => {
console.log(`Server is started on port ${port}`);
});
} catch (error) {
console.log(error);
}
}
start();

View File

@ -0,0 +1,9 @@
import { ApiErrorHandler } from "../error/api-error.handler.js"
export function ErrorHandlingMiddleware(err, req, res, next) {
if (err instanceof ApiErrorHandler) {
return res.status(err.status).json({message: err.message})
}
return res.status(500).json({message: "Непредвиденная ошибка"})
}

View File

@ -0,0 +1,8 @@
import { DataTypes } from "sequelize";
export const customCreatedAndUpdatedFields = {
createdAt: "created_at",
updatedAt: "updated_at"
};
export const idSettingsObject = { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true };

0
server/models/models.js Normal file
View File

1896
server/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

26
server/package.json Normal file
View File

@ -0,0 +1,26 @@
{
"dependencies": {
"argon2": "^0.31.2",
"cors": "^2.8.5",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"pg": "^8.11.3",
"pg-hstore": "^2.3.4",
"sequelize": "^6.33.0"
},
"devDependencies": {
"@faker-js/faker": "^8.3.1",
"nodemon": "^3.0.1"
},
"name": "server",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"server": "nodemon index.js",
"seed": "node seeder/seeder.js"
},
"author": "",
"license": "ISC",
"description": "",
"type": "module"
}

3
server/routes/routes.js Normal file
View File

@ -0,0 +1,3 @@
import { Router } from "express";
export const router = new Router();

View File

View File

View File

View File

View File

0
server/seeder/seeder.js Normal file
View File