diff --git a/backend/server.js b/backend/server.js
index 66801f5..1327d36 100644
--- a/backend/server.js
+++ b/backend/server.js
@@ -64,6 +64,7 @@ if (!carCols.includes('has_etc')) {
if (!carCols.includes('tire_type')) {
db.exec("ALTER TABLE cars ADD COLUMN tire_type TEXT DEFAULT 'ノーマル'");
}
+db.prepare("UPDATE cars SET tire_type = 'スタッドレス' WHERE tire_type = 'スタットレス'").run();
// Seed some initial cars if none exist
const carCount = db.prepare('SELECT COUNT(*) as cnt FROM cars').get();
@@ -86,13 +87,27 @@ function broadcast(message) {
});
}
+function normalizeTireType(value) {
+ return value === 'スタットレス' ? 'スタッドレス' : value;
+}
+
+function normalizeCar(car) {
+ if (!car) {
+ return car;
+ }
+ return {
+ ...car,
+ tire_type: normalizeTireType(car.tire_type),
+ };
+}
+
wss.on('connection', (ws) => {
ws.on('error', () => {}); // suppress unhandled error events
});
// --- Cars API ---
app.get('/api/cars', (req, res) => {
- const cars = db.prepare('SELECT * FROM cars ORDER BY id').all();
+ const cars = db.prepare('SELECT * FROM cars ORDER BY id').all().map(normalizeCar);
res.json(cars);
});
@@ -104,7 +119,7 @@ app.post('/api/cars', (req, res) => {
const result = db.prepare(
'INSERT INTO cars (name, description, inspection_expiry, has_etc, tire_type) VALUES (?, ?, ?, ?, ?)'
).run(name.trim(), description, inspection_expiry, has_etc ? 1 : 0, tire_type);
- const car = db.prepare('SELECT * FROM cars WHERE id = ?').get(result.lastInsertRowid);
+ const car = normalizeCar(db.prepare('SELECT * FROM cars WHERE id = ?').get(result.lastInsertRowid));
broadcast({ type: 'data_changed', entity: 'cars' });
res.status(201).json(car);
});
@@ -120,7 +135,7 @@ app.put('/api/cars/:id', (req, res) => {
if (result.changes === 0) {
return res.status(404).json({ error: '車が見つかりません' });
}
- const car = db.prepare('SELECT * FROM cars WHERE id = ?').get(req.params.id);
+ const car = normalizeCar(db.prepare('SELECT * FROM cars WHERE id = ?').get(req.params.id));
broadcast({ type: 'data_changed', entity: 'cars' });
res.json(car);
});
diff --git a/car-login.html b/car-login.html
new file mode 100644
index 0000000..8cd9ecc
--- /dev/null
+++ b/car-login.html
@@ -0,0 +1,112 @@
+
+
+
+
+
+ ログイン
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/frontend/src/api.js b/frontend/src/api.js
index 55a7aa5..4ceadf7 100644
--- a/frontend/src/api.js
+++ b/frontend/src/api.js
@@ -1,8 +1,13 @@
const API_BASE = (import.meta.env.VITE_API_BASE_URL ?? '') + '/api';
async function request(path, options = {}) {
+ const hasBody = options.body !== undefined;
const res = await fetch(`${API_BASE}${path}`, {
- headers: { 'Content-Type': 'application/json' },
+ credentials: 'include',
+ headers: {
+ ...(hasBody ? { 'Content-Type': 'application/json' } : {}),
+ ...(options.headers ?? {}),
+ },
...options,
});
if (!res.ok) {
diff --git a/frontend/src/components/CarManagement.jsx b/frontend/src/components/CarManagement.jsx
index 5202b17..a4ba5ee 100644
--- a/frontend/src/components/CarManagement.jsx
+++ b/frontend/src/components/CarManagement.jsx
@@ -169,7 +169,7 @@ export default function CarManagement({ reloadKey = 0 }) {
onChange={(e) => setNewCarTire(e.target.value)}
>
-
+