ruscomap/index.js
2024-07-17 12:00:34 +02:00

53 lines
1.4 KiB
JavaScript

const express = require('express')
const multer = require('multer')
const config = require('config');
const dbHandler = require('./dbHandler.js')
const app = express()
const port = config.get('app.port')
const upload = multer({ dest: config.get('app.upload')})
app.use(express.static('public'))
app.use('/imgs', express.static(config.get('app.upload')))
app.use(express.json()) // for json
app.use(express.urlencoded({ extended: true, limit: '12MB', parameterLimit: 100000 })); // support encoded bodies
app.get('/', (req, res) => {
res.sendFile(__dirname + './public/index.html');
})
app.post('/uploadMarker', upload.single('image'),(req, res) => {
const data = req.body
image = req.file
// Extract marker data
const newMarker = {
name: data.name,
description: data.description,
filename: image.filename,
long: data.long,
lat: data.lat,
}
// Add marker to db
dbHandler.addMarker(newMarker);
})
app.get('/fetchMarkers', (req, res) => {
dbHandler.getAllMarkers((rows) => {
res.status(200).json(rows);
});
})
app.get('/updateMarkers', (req, res) => {
const data = req.query
console.log(data.fromDate)
dbHandler.getUpdatedMarkers(data.fromDate, (rows) => {
res.status(200).json(rows);
});
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})