Untitled
unknown
plain_text
3 years ago
4.6 kB
1
Indexable
Never
const express = require('express'); const mongoose = require('mongoose') const csv = require('csv-parser') const fs= require('fs') const app =express(); const path =require('path'); const mysql = require('mysql2'); const bodyParser = require('body-parser'); const user = require('./data.js') app.use(express.json()); app.use(express.urlencoded({ extended: true })) app.use(bodyParser.json()); app.use(bodyParser.raw()) app.use(bodyParser.urlencoded({ extended: true })); app.listen(3000) const result =[] const zmq = require('zeromq') /*fs.createReadStream('car4_data.csv').pipe(csv({})).on('data',(data)=>result.push(data)).on('end',() => {}); const sock = new zmq.Push(); run(); async function run () { await sock.bind("tcp://127.0.0.1:3000"); console.log("Server is ready listening on port 3000"); console.log("Press any key to start sending the jobs!") process.stdin.once("data", send); } //sending the jobs to the workers async function send () { console.log("About to send jobs!"); for (let i = 0 ;i < result.length; i++) { await sock.send(JSON.stringify(result[i])); //wait 500ms await new Promise(resolve => setTimeout(resolve, 200)) } }*/ var connection = mysql.createConnection({ connectionLimit:10, host: 'localhost', user: 'root', password: '3005', database: 'user' }); connection.connect(function(error){ if(error){ console.log("err") } else{ console.log('connected') } }) app.get('/',(req,res)=>{ res.sendFile(path.join(__dirname,'index.html')); }); app.get('/map',(req,res)=>{ res.sendFile(path.join(__dirname,'map.html')); }); var userID,time,id,time1,id1; app.post("/search", (req, res, next) => { time=req.body.time; id=req.body.id; time1=req.body.time1; id1=req.body.id1; }); app.get('/files2',async (req,res,next)=>{ const l = await user.find({$and: [ { time:time }, { id:id } ]}).exec(); const t= JSON.stringify(l) const a=JSON.parse(t) const l1 = await user.find({$and: [ { int:{ $gt: a[0].int } }, { int:{ $lt: a[0].int+0.020833 } } ]}).exec(); const t1= JSON.stringify(l1) const a1=JSON.parse(t1) res.json(a1) }); app.get('/files1',async (req,res,next)=>{ console.log(time1) console.log(id1) console.log(time) console.log(id) const l = await user.find({$and: [ { time:time1 }, { id:id1 } ]}).exec(); const t= JSON.stringify(l) const a=JSON.parse(t) const l1 = await user.find({$and: [ { int:{ $gt: a[0].int-0.020833 } }, { int:{ $lt: a[0].int } } ]}).exec(); const t1= JSON.stringify(l1) const a1=JSON.parse(t1) res.json(a1) }); app.get('/files',async (req,res,next)=>{ const l = await user.find({$and: [ { time:time }, { id:id }]}).exec(); const t= JSON.stringify(l) const a=JSON.parse(t) const l1 = await user.find({$and: [ { int:{ $gt: a[0].int - 0.020833 } }, { int:{ $lt: a[0].int } } ]}).exec(); const t1= JSON.stringify(l1) const a1=JSON.parse(t1) res.json(a1) }); var count=0; app.post("/submit", (req, res, next) => { userID=req.body.password; if(req.body.password==" "&& req.body.name==" "){ return res.status(500).json({ message:"Make sure there isn't any empty field" }); } else if(req.body.password==""|| req.body.name==""){ return res.status(500).json({ message:"Make sure there isn't any empty field" }); } else{ connection.query('SELECT * FROM `login`' , (err, rows) => { if (err) { console.log("Error") } else{ console.log("success") for(let i=0;i<rows.length;i++){ if(rows[i].username==req.body.name && rows[i].password==req.body.password ) { res.redirect('/map') } else{ console.log(count) if(count===3){ res.sendFile(path.join(__dirname,'msg.html')) count=0; } else{ res.sendFile(path.join(__dirname,'index.html')) count +=1; } } } } }) } })