-
Notifications
You must be signed in to change notification settings - Fork 120
6411 Домнин.Н.М. Лаб.2 Вар.2 #105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
exxxpm
wants to merge
2
commits into
itsecd:main
Choose a base branch
from
exxxpm:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| root = true | ||
|
|
||
| [*] | ||
| charset = utf-8 | ||
| end_of_line = lf | ||
| insert_final_newline = true | ||
| indent_style = space | ||
| indent_size = 4 | ||
| trim_trailing_whitespace = true | ||
|
|
||
| [*.md] | ||
| trim_trailing_whitespace = false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| .DS_Store | ||
| .playwright-cli/ | ||
| .cache/ | ||
| backend/node_modules/ | ||
| backend/.cache/ | ||
| backend/.env | ||
| backend/package-lock.json | ||
| client/node_modules/ | ||
| client/dist/ | ||
| client/.env | ||
| client/package-lock.json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "tabWidth": 4, | ||
| "useTabs": false, | ||
| "semi": true, | ||
| "singleQuote": false, | ||
| "trailingComma": "all", | ||
| "printWidth": 100 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| PORT=3001 | ||
| CLIENT_ORIGIN=http://localhost:5173 | ||
| CLIENT_ORIGINS=http://localhost:5173,http://127.0.0.1:5173,http://localhost:4173,http://127.0.0.1:4173,http://localhost:4174,http://127.0.0.1:4174 | ||
| YANDEX_RASP_API_KEY= | ||
| YANDEX_RASP_API_BASE=https://api.rasp.yandex-net.ru/v3.0 | ||
| STATION_CACHE_MAX_AGE_HOURS=24 | ||
| STATION_SEARCH_LIMIT=12 | ||
| NEAREST_STATION_LIMIT=8 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import "dotenv/config"; | ||
|
|
||
| export const PORT = Number(process.env.PORT || 3001); | ||
| export const CLIENT_ORIGIN = process.env.CLIENT_ORIGIN || "http://localhost:5173"; | ||
| export const CLIENT_ORIGINS = String(process.env.CLIENT_ORIGINS || CLIENT_ORIGIN) | ||
| .split(",") | ||
| .map((origin) => origin.trim()) | ||
| .filter(Boolean); | ||
| export const YANDEX_RASP_API_KEY = process.env.YANDEX_RASP_API_KEY || ""; | ||
| export const YANDEX_RASP_API_BASE = | ||
| process.env.YANDEX_RASP_API_BASE || "https://api.rasp.yandex-net.ru/v3.0"; | ||
| export const STATION_CACHE_MAX_AGE_HOURS = Number(process.env.STATION_CACHE_MAX_AGE_HOURS || 24); | ||
| export const STATION_SEARCH_LIMIT = Number(process.env.STATION_SEARCH_LIMIT || 12); | ||
| export const NEAREST_STATION_LIMIT = Number(process.env.NEAREST_STATION_LIMIT || 8); | ||
|
|
||
| export const RAIL_STATION_TYPES = [ | ||
| "station", | ||
| "platform", | ||
| "stop", | ||
| "checkpoint", | ||
| "post", | ||
| "crossing", | ||
| "overtaking_point", | ||
| "train_station", | ||
| "unknown", | ||
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| { | ||
| "name": "suburban-backend", | ||
| "private": true, | ||
| "type": "module", | ||
| "scripts": { | ||
| "dev": "node --watch server.js", | ||
| "start": "node server.js" | ||
| }, | ||
| "dependencies": { | ||
| "cors": "^2.8.5", | ||
| "dotenv": "^16.4.7", | ||
| "express": "^4.21.2" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| import cors from "cors"; | ||
| import express from "express"; | ||
| import { CLIENT_ORIGINS, NEAREST_STATION_LIMIT, PORT, STATION_SEARCH_LIMIT } from "./config.js"; | ||
| import { searchNearbyStationsFromIndex, searchStationsByName } from "./services/stationIndex.js"; | ||
| import { getStationSchedule, searchRoutesBetweenStations } from "./services/yandexRasp.js"; | ||
|
|
||
| const app = express(); | ||
|
|
||
| function isAllowedOrigin(origin) { | ||
| if (!origin) { | ||
| return true; | ||
| } | ||
|
|
||
| if (CLIENT_ORIGINS.includes(origin)) { | ||
| return true; | ||
| } | ||
|
|
||
| return /^https?:\/\/(localhost|127\.0\.0\.1)(:\d+)?$/.test(origin); | ||
| } | ||
|
|
||
| app.use( | ||
| cors({ | ||
| origin(origin, callback) { | ||
| if (isAllowedOrigin(origin)) { | ||
| callback(null, true); | ||
| return; | ||
| } | ||
|
|
||
| callback(new Error(`CORS blocked for origin: ${origin}`)); | ||
| }, | ||
| }), | ||
| ); | ||
| app.use(express.json()); | ||
|
|
||
| function sendError(response, error, fallbackMessage) { | ||
| console.error("[api]", error); | ||
| response.status(error.statusCode || 500).json({ | ||
| error: error.message || fallbackMessage, | ||
| }); | ||
| } | ||
|
|
||
| app.get("/api/ping", (_request, response) => { | ||
| response.json({ | ||
| ok: true, | ||
| now: new Date().toISOString(), | ||
| }); | ||
| }); | ||
|
|
||
| app.get("/api/stations/suggest", async (request, response) => { | ||
| try { | ||
| const searchText = String(request.query.searchText || ""); | ||
| const limit = Number(request.query.limit || STATION_SEARCH_LIMIT); | ||
| const stations = await searchStationsByName(searchText, limit); | ||
|
|
||
| response.json({ | ||
| stations, | ||
| }); | ||
| } catch (error) { | ||
| sendError(response, error, "Не удалось выполнить поиск станций."); | ||
| } | ||
| }); | ||
|
|
||
| app.get("/api/stations/nearby", async (request, response) => { | ||
| try { | ||
| const latitude = Number(request.query.lat); | ||
| const longitude = Number(request.query.lng); | ||
| const distance = Number(request.query.distance || 15); | ||
| const limit = Number(request.query.limit || NEAREST_STATION_LIMIT); | ||
|
|
||
| if (!Number.isFinite(latitude) || !Number.isFinite(longitude)) { | ||
| response.status(400).json({ | ||
| error: "Для поиска по карте нужны координаты lat и lng.", | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| const stations = await searchNearbyStationsFromIndex(latitude, longitude, distance, limit); | ||
|
|
||
| response.json({ | ||
| stations, | ||
| }); | ||
| } catch (error) { | ||
| sendError(response, error, "Не удалось получить станции рядом с выбранной точкой."); | ||
| } | ||
| }); | ||
|
|
||
| app.get("/api/stations/:stationCode/schedule", async (request, response) => { | ||
| try { | ||
| const stationCode = String(request.params.stationCode || ""); | ||
| const date = String(request.query.date || ""); | ||
|
|
||
| if (!stationCode) { | ||
| response.status(400).json({ | ||
| error: "Не передан код станции.", | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| const schedule = await getStationSchedule(stationCode, date); | ||
| response.json(schedule); | ||
| } catch (error) { | ||
| sendError(response, error, "Не удалось загрузить расписание по станции."); | ||
| } | ||
| }); | ||
|
|
||
| app.get("/api/routes/search", async (request, response) => { | ||
| try { | ||
| const fromStationCode = String(request.query.from || ""); | ||
| const toStationCode = String(request.query.to || ""); | ||
| const date = String(request.query.date || ""); | ||
|
|
||
| if (!fromStationCode || !toStationCode) { | ||
| response.status(400).json({ | ||
| error: "Для поиска маршрута нужно выбрать станции отправления и прибытия.", | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| const routes = await searchRoutesBetweenStations(fromStationCode, toStationCode, date); | ||
| response.json(routes); | ||
| } catch (error) { | ||
| sendError(response, error, "Не удалось загрузить маршруты между станциями."); | ||
| } | ||
| }); | ||
|
|
||
| app.listen(PORT, () => { | ||
| console.log(`Backend started on http://localhost:${PORT}`); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А может просто ['*']?