Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions electric_train/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
REACT_APP_API_KEY=5c35214b-1ca9-4216-a86e-d852deeecfaf
REACT_APP_PROXY_URL=http://localhost:3001/api/rasp
23 changes: 23 additions & 0 deletions electric_train/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
52 changes: 52 additions & 0 deletions electric_train/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "electric_train",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/dom": "^10.4.1",
"@testing-library/jest-dom": "^6.9.1",
"@testing-library/react": "^16.3.2",
"@testing-library/user-event": "^13.5.0",
"bootstrap": "^5.3.0",
"cors": "^2.8.6",
"dotenv": "^17.4.0",
"express": "^5.2.1",
"leaflet": "^1.9.4",
"node-fetch": "^2.7.0",
"ol": "^10.8.0",
"react": "^19.2.4",
"react-bootstrap": "^2.10.0",
"react-dom": "^19.2.4",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"start:all": "concurrently \"npm run server\" \"npm run start\"",
"server": "node server.js",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"concurrently": "^9.1.2"
}
}
Binary file added electric_train/public/favicon.ico
Binary file not shown.
43 changes: 43 additions & 0 deletions electric_train/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.

Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.

To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
Comment on lines +13 to +41
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Комментарии в целом можно удалить и тег <noscript>

</body>
</html>
Binary file added electric_train/public/logo192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added electric_train/public/logo512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions electric_train/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
3 changes: 3 additions & 0 deletions electric_train/public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
47 changes: 47 additions & 0 deletions electric_train/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const express = require('express');
const cors = require('cors');
const fetch = require('node-fetch');
require('dotenv').config();

const app = express();
const port = 3001;

const API_KEY = process.env.REACT_APP_API_KEY || '5c35214b-1ca9-4216-a86e-d852deeecfaf';
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лучше вот так

const API_KEY = process.env.REACT_APP_API_KEY ?? null;

if (!API_KEY) {
    console.error("Invalid API_KEY")
    return;
}


app.use(cors());
app.use(express.json());

app.use('/api/rasp', async (req, res) => {
try {
const apiPath = req.originalUrl.replace('/api/rasp', '');
const separator = apiPath.includes('?') ? '&' : '?';
const targetUrl = `https://api.rasp.yandex.net/v3.0${apiPath}${separator}apikey=${API_KEY}`;

console.log('Прокси запрос к:', targetUrl.replace(API_KEY, '***HIDDEN***'));

const response = await fetch(targetUrl, {
headers: {
'Accept': 'application/json',
'User-Agent': 'Mozilla/5.0'
}
});

const text = await response.text();

try {
const data = JSON.parse(text);
res.json(data);
} catch (e) {
console.error('Ошибка парсинга JSON');
res.status(500).json({ error: 'API вернул невалидный JSON' });
}

} catch (error) {
console.error('Ошибка прокси:', error.message);
res.status(500).json({ error: 'Ошибка при выполнении запроса к API' });
}
});

app.listen(port, () => {
console.log(`✅ Прокси сервер запущен на http://localhost:${port}`);
});
144 changes: 144 additions & 0 deletions electric_train/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
.App {
min-height: 100vh;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.app-header {
background: rgba(255, 255, 255, 0.95);
padding: 1rem;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
text-align: center;
}

.app-header h1 {
margin: 0;
font-size: 1.5rem;
color: #333;
}

.app-header p {
margin: 0.5rem 0 0;
font-size: 0.9rem;
color: #666;
}

.map-container {
height: 100vh;
padding: 0;
position: relative;
}

.map-container > div {
height: 100%;
width: 100%;
}

.ol-map {
width: 100%;
height: 100%;
min-height: 500px;
}

.ol-viewport {
border-radius: 0;
}

.sidebar {
background: white;
height: 100vh;
overflow-y: auto;
padding: 1rem;
box-shadow: -2px 0 10px rgba(0, 0, 0, 0.1);
}

.nav-tabs {
margin-bottom: 1rem;
}

.nav-tabs .nav-link {
color: #667eea;
font-weight: 500;
}

.nav-tabs .nav-link.active {
background-color: #667eea;
color: white;
border-color: #667eea;
}

.tab-content {
padding: 1rem 0;
}

@media (max-width: 768px) {
.map-container {
height: 50vh;
}

.sidebar {
height: 50vh;
}

.app-header h1 {
font-size: 1.2rem;
}
}

.ol-popup {
position: absolute;
background-color: white;
padding: 10px;
border-radius: 8px;
border: 1px solid #ccc;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
font-size: 14px;
min-width: 150px;
z-index: 1000;
}

.ol-popup:before {
content: '';
position: absolute;
bottom: -10px;
left: 50%;
transform: translateX(-50%);
border-width: 10px 10px 0;
border-style: solid;
border-color: white transparent transparent;
}

.ol-popup button {
margin-top: 8px;
padding: 5px 10px;
background-color: #667eea;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
width: 100%;
}

.ol-popup button:hover {
background-color: #5a67d8;
}

.station-search .station-item {
cursor: pointer;
transition: background-color 0.2s;
}

.station-search .station-item:hover {
background-color: #f8f9fa;
}

.schedule-item {
transition: background-color 0.2s;
}

.schedule-item:hover {
background-color: #f8f9fa;
}

.route-results {
margin-top: 1rem;
}
Loading