Обновил бэкенд под новые изменения на фронте
This commit is contained in:
41
server.js
Normal file
41
server.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import express from 'express'
|
||||
import Database from 'sqlite3'
|
||||
import { fileURLToPath } from 'url'
|
||||
import { dirname, join } from 'path'
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url))
|
||||
const app = express()
|
||||
const PORT = 3000
|
||||
|
||||
const db = new Database.Database(join(__dirname, 'Buh-nr'))
|
||||
|
||||
app.use(express.static(join(__dirname, 'dist')))
|
||||
|
||||
app.get('/api/regions', (_req, res) => {
|
||||
db.all('SELECT id, name, slug FROM regions ORDER BY id', (err, rows) => {
|
||||
if (err) return res.status(500).json({ error: 'Ошибка получения регионов' })
|
||||
res.json(rows)
|
||||
})
|
||||
})
|
||||
|
||||
app.get('/api/tariffs', (req, res) => {
|
||||
const mode = req.query.mode || 'special'
|
||||
const sql = `
|
||||
SELECT t.id, t.title, t.description, p.price
|
||||
FROM tariffs t
|
||||
JOIN prices p ON p.tariff_id = t.id
|
||||
JOIN tax_modes tm ON tm.id = p.tax_mode_id
|
||||
WHERE tm.slug = ?
|
||||
ORDER BY t.sort_order
|
||||
`
|
||||
db.all(sql, [mode], (err, rows) => {
|
||||
if (err) return res.status(500).json({ error: 'Ошибка получения тарифов' })
|
||||
res.json(rows)
|
||||
})
|
||||
})
|
||||
|
||||
app.get('/{*splat}', (_req, res) => {
|
||||
res.sendFile(join(__dirname, 'dist', 'index.html'))
|
||||
})
|
||||
|
||||
app.listen(PORT, () => console.log(`Сервер запущен: http://localhost:${PORT}`))
|
||||
Reference in New Issue
Block a user