Skip to content
This repository was archived by the owner on Jun 19, 2024. It is now read-only.

Commit d9b47cb

Browse files
committed
updated correct status codes
1 parent 2c7e25e commit d9b47cb

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

api.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ http.createServer(function (req, res) {
1414
res.write(fileContents);
1515
res.end();
1616
}
17-
else if (req.url === '/home.js') {
18-
res.writeHead(200, {'Content-type' : 'text/javascript'});
19-
var fileContents = fs.readFileSync('./home.js', {encoding: 'utf8'});
20-
res.write(fileContents);
21-
res.end();
22-
}
2317
else if (req.url === '/'){
2418
fs.readFile('./home.html', null, function(err, data){
2519
if(err){
@@ -53,11 +47,12 @@ http.createServer(function (req, res) {
5347
var cursor = collection.find(query, {fields: fields}).sort({"date": -1}).limit(1).toArray(function(err, result) {
5448
if (err) throw err;
5549
dbo.close();
56-
res.writeHead(200, {'Content-Type': 'text/json'});
5750
if(result[0]){
51+
res.writeHead(200, {'Content-Type': 'text/json'});
5852
res.write(JSON.stringify(result[0]));
5953
}else{
60-
res.write(JSON.stringify({}))
54+
res.writeHead(400, {'Content-Type': 'text/json'});
55+
res.write(JSON.stringify({"error":"Invalid base or symbols"}))
6156
}
6257
res.end();
6358
});
@@ -83,11 +78,12 @@ http.createServer(function (req, res) {
8378
var cursor = collection.find(query, {fields: fields}).toArray(function(err, result) {
8479
if (err) throw err;
8580
dbo.close();
86-
res.writeHead(200, {'Content-Type': 'text/json'});
8781
if(result[0]){
82+
res.writeHead(200, {'Content-Type': 'text/json'});
8883
res.write(JSON.stringify(result[0]));
8984
}else{
90-
res.write(JSON.stringify({}))
85+
res.writeHead(400, {'Content-Type': 'text/json'});
86+
res.write(JSON.stringify({"error":"Invalid base or symbols"}))
9187
}
9288
res.end();
9389
});

0 commit comments

Comments
 (0)