62 lines
1.6 KiB
JavaScript
62 lines
1.6 KiB
JavaScript
const express = require('express')
|
|
const multer = require('multer')
|
|
const schedule = require('node-schedule');
|
|
|
|
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')})
|
|
|
|
const job = schedule.scheduleJob('* * 23 * *', function(){
|
|
console.log('Deleting markers older than choosen time limit');
|
|
const timeLimit = 24;
|
|
dbHandler.deleteMarkersOlderThanTimeLimit(timeLimit);
|
|
|
|
});
|
|
|
|
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}`)
|
|
})
|