-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
72 lines (60 loc) · 1.74 KB
/
server.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
var pt=require('periodic-table');
var express = require('express');
var morgan = require('morgan');
var path = require('path');
var app = express();
app.use(morgan('combined'));
app.get('/', function (req, res) {
res.sendFile(path.join(__dirname, 'ui', 'index.html'));
});
app.get('/jQuery.js', function (req, res) {
res.sendFile(path.join(__dirname, 'jQuery.js'));
});
app.get('/up.png', function (req, res) {
res.sendFile(path.join(__dirname, 'up.png'));
});
app.get('/searchicon.png', function (req, res) {
res.sendFile(path.join(__dirname, 'searchicon.png'));
});
app.get('/favicon.png', function(req,res) {
res.sendFile(path.join(__dirname,'favicon.png'));
});
app.get('/ui/main.js', function (req, res) {
res.sendFile(path.join(__dirname, 'ui', 'main.js'));
});
app.get('/ui/theme.css', function (req, res) {
res.sendFile(path.join(__dirname, 'ui', 'theme.css'));
});
app.get('/fetch-details', function(req, res) {
var id=parseInt(req.query.id);
res.send(JSON.stringify(pt.numbers[id]));
});
app.get('/search', function(req,res) {
var key=req.query.key;
var i=1;
if(isNaN(key)) {
if(key.length<=2) {
while(i<119) {
if(pt.numbers[i].symbol.toLowerCase() === key.toLowerCase()) res.send(JSON.stringify(pt.numbers[i]));
i++;
}
res.sendStatus(404);
}
else{
while(i<119){
if(pt.numbers[i].name.toLowerCase() === key.toLowerCase()) res.send(JSON.stringify(pt.numbers[i]));
i++;
}
res.sendStatus(404);
}
}
else {
var num=parseInt(key);
if(num>0 && num<119) res.send(pt.numbers[num]);
else res.sendStatus(404);
}
});
const PORT = process.env.PORT || 80
app.listen(PORT, function () {
console.log(`Listening on ${PORT}!`);
});