// @deno-types="npm:@types/express" import express, { Request, Response } from 'express'; import cors from 'cors'; import {firstPoint, getCollisionPoints, interpolation} from "./physics.ts"; import {changeBasis} from "./math.ts"; const app = express(); const PORT = 3000; app.use(cors()); app.get('/api/points', (req: Request, res: Response) => { const { g, h, l, alpha } = req.query; if (g === undefined || h === undefined || l === undefined || alpha === undefined) { res.status(401).send("Параметры должны быть заданы"); } res.json( getCollisionPoints({ g: Number(g), h: Number(h), l: Number(l), alpha: Number(alpha) }) ); }); app.get('/api/interpolation', (req: Request, res: Response) => { const { g, h, l, alpha, count } = req.query; if (g === undefined || h === undefined || l === undefined || alpha === undefined || count === undefined) { res.status(401).send("Параметры должны быть заданы"); } const params = { g: Number(g), h: Number(h), l: Number(l), alpha: Number(alpha) }; const fp = firstPoint(params); res.json([...fp, ...changeBasis(interpolation(params), -Number(alpha)).map(p => ({...p, y: p.y - Number(h), time: p.time + fp[fp.length - 1].time}))]); }); app.listen(PORT, () => { console.log(`Сервер запущен на http://localhost:${PORT}`); });