This repository has been archived by the owner on Jul 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
115 lines (101 loc) · 2.57 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//jshint esversion:6
const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const querystring = require('querystring');
const app = express();
app.use(express.static('public'));
//q4QbxT9vVV5WW6DO
mongoose.connect("mongodb+srv://admin:q4QbxT9vVV5WW6DO@cluster0-hc4da.mongodb.net/SCISAT_Data", {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false
});
testSchema = {
name: String,
description: String
};
pointSchema = {
_id: Number,
x: Number,
y: Number
};
concentrationSchema = {
_id: mongoose.Schema.ObjectId,
occultation_name: [String],
event_type: [String],
date: [String],
date_MJD2000: [String],
latitude: [String],
longitude: [String],
beta_angle: [String],
start_timetag: [String],
end_timetag: [String],
start_time: [String],
end_time: [String],
molecule_range: [String],
molecule_name: [String],
alt_conc: [[mongoose.Schema.Number]]
}
function insertTest(){
for (let i = 0;i < 5000; i++ ){
const point = new Point({
_id: i,
x : Math.floor( Math.random() * 50),
y: Math.floor( Math.random() * 50)
});
point.save();
}
}
const Test = mongoose.model("Test", testSchema);
const Point = mongoose.model("Point", pointSchema);
const Ozone = mongoose.model("TimePeriod", concentrationSchema, "TimePeriod");
app.use(bodyParser.urlencoded({
extended: true
}));
app.route("/:paramName").get(function(req, res) {
// insertTest();
const path = req.params.paramName;
console.log(path);
res.sendFile(__dirname+"/public/index.html");
});
app.route("/api/:paramName")
.get(function(req, res) {
const queryObject = req.query;
const q = queryObject.q;
const collection = req.params.paramName;
if (collection === "points") {
Point.find({}, (err, foundItems) => {
if(err){
res.send(err);
} else {
res.send({Data:foundItems});
}
});
} else if(collection==="tests") {
console.log(q);
Test.find({name: q}, (err, foundItems) => {
if(err){
res.send(err);
} else {
res.send(foundItems);
}
});
} else if(collection === "Data" && q){
Ozone.find({date:{$regex:q+".*"}}, (err, foundItems)=>{
if (err){
res.send(err);
} else {
//console.log(foundItems);
res.send({Data:foundItems});
}
});
}
});
let port = process.env.PORT;
if (port == null || port == ""){
port = 3000;
}
app.listen(port, function(){
console.log("Server started on port "+port);
});