콘솔메세지추가

This commit is contained in:
2026-02-06 16:12:20 +09:00
parent a231d024b5
commit 91d7817bb8
2 changed files with 20 additions and 3 deletions

View File

@@ -20,8 +20,9 @@ app.use(express.json());
let db;
async function initializeDB() {
const dbPath = path.join(__dirname, 'wifi_markers.db');
db = await open({
filename: path.join(__dirname, 'wifi_markers.db'),
filename: dbPath,
driver: sqlite3.Database
});
@@ -46,13 +47,16 @@ async function initializeDB() {
)
`);
console.log('Database initialized with WAL mode enabled.');
console.log(`[DB] Database initialized at: ${dbPath}`);
console.log('[DB] WAL mode enabled for concurrent writes.');
}
// Routes
app.get('/api/markers', async (req, res) => {
console.log(`[API] GET /api/markers - Fetching markers from SQLite`);
try {
const markers = await db.all('SELECT * FROM markers');
console.log(`[API] Found ${markers.length} markers`);
// Convert isPublic from 0/1 to boolean
const formattedMarkers = markers.map(m => ({
...m,
@@ -67,6 +71,7 @@ app.get('/api/markers', async (req, res) => {
app.post('/api/markers', async (req, res) => {
const { id, name, ssid, password, lat, lng, securityType, iconType, description, addedBy, createdAt, isPublic } = req.body;
console.log(`[API] POST /api/markers - Saving marker: ${name} (${ssid}) to SQLite`);
try {
await db.run(`
@@ -74,6 +79,7 @@ app.post('/api/markers', async (req, res) => {
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
`, [id, name, ssid, password, lat, lng, securityType, iconType, description || '', addedBy, createdAt, isPublic ? 1 : 0]);
console.log(`[API] Successfully saved marker: ${id}`);
res.json({ success: true });
} catch (error) {
console.error(error);
@@ -83,8 +89,10 @@ app.post('/api/markers', async (req, res) => {
app.delete('/api/markers/:id', async (req, res) => {
const { id } = req.params;
console.log(`[API] DELETE /api/markers/${id} - Deleting marker from SQLite`);
try {
await db.run('DELETE FROM markers WHERE id = ?', [id]);
console.log(`[API] Successfully deleted marker: ${id}`);
res.json({ success: true });
} catch (error) {
console.error(error);