forked from apis-is/apis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New pattern for loading endpoints. More tests and fixes in various fu…
…nctions
- Loading branch information
1 parent
7fd7271
commit 29ab9ba
Showing
18 changed files
with
92 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
//Possible endpoint: | ||
//https://www.isnic.is/is/whois/mini.php?type=all&query=apis.is | ||
//https://www.isnic.is/is/whois/mini.php?type=all&query=apis.is | ||
exports.setup = function(){ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
exports.setup = function(){ | ||
server.post({path: '/help_out', version: '1.0.0'}, function(req, res, next){ | ||
res.json(200,{message:'Send us mail: [email protected] ,thanks for your interest!'}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
exports.setup = function(){ | ||
server.post({path: '/phone', version: '1.0.0'}, function(req, res, next){ | ||
res.json(410,{error:"This api endpoint has been closed and it will not be available in the foreseeable future."}); | ||
return next(); | ||
}); | ||
server.post({path: '/phone', version: '2.0.0'}, function(req, res, next){ | ||
res.json(410,{error:"This api endpoint has been closed and it will not be available in the foreseeable future."}); | ||
return next(); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,16 @@ | ||
/** | ||
* Registers an endpoint onto the server handle | ||
*/ | ||
function register(endpoint,data){ | ||
console.log('- '+endpoint); | ||
switch(endpoint){ | ||
case 'frontpage': | ||
server.get({path: '/'}, data.getSlash); | ||
server.post({path: '/'}, data.postSlash); | ||
break; | ||
case 'bus': | ||
server.post({path: '/bus/search', version: '1.0.0'}, data.search); | ||
server.post({path: '/bus/realtime', version: '1.0.0'}, data.realtime); | ||
break; | ||
case 'sms': | ||
server.post({path: '/sms', version: '1.0.0'}, data.slash); | ||
break; | ||
case 'currency': | ||
server.post({path: '/currency', version: '1.0.0'}, data.slash); | ||
break; | ||
case 'currency.m5': | ||
server.get({path: '/currency/m5', version: '1.0.0'}, data.slash); | ||
break; | ||
case 'currency.arion': | ||
server.get({path: '/currency/arion', version: '1.0.0'}, data.slash); | ||
break; | ||
case 'company': | ||
server.post({path: '/company', version: '1.0.0'}, data.slash); | ||
break; | ||
case 'car': | ||
server.post({path: '/car', version: '1.0.0'}, data.slash); | ||
break; | ||
case 'flight': | ||
server.post({path: '/flight', version: '1.0.0'}, data.slash); | ||
break; | ||
case 'house': | ||
//Incomplete | ||
server.post({path: '/house', version: '1.0.0'}, data.slash); | ||
break; | ||
case 'word': | ||
//Incomplete | ||
server.post({path: '/word', version: '1.0.0'}, data.slash); | ||
break; | ||
case 'phone': | ||
server.post({path: '/phone', version: '1.0.0'}, function(req, res, next){ | ||
res.json(410,{error:"This api endpoint has been closed and it will not be available in the foreseeable future."}); | ||
return next(); | ||
}); | ||
server.post({path: '/phone', version: '2.0.0'}, function(req, res, next){ | ||
res.json(410,{error:"This api endpoint has been closed and it will not be available in the foreseeable future."}); | ||
return next(); | ||
}); | ||
break; | ||
case 'help_out': | ||
server.post({path: '/help_out', version: '1.0.0'}, function(req, res, next){ | ||
res.json(200,{message:'Send us mail: [email protected] ,thanks for your interest!'}); | ||
}); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
/** | ||
* Loads upp all the required endpoints | ||
*/ | ||
exports.load = function(){ | ||
console.log('Registering endpoints:'); | ||
exports.load = function(){ | ||
//Load all endpoints in the endpoints folder | ||
//walk is blocking on purpose because the server can't listen yet | ||
fileModule.walk('./endpoints', function(a, dirPath, dirs, files){ | ||
if(files){ | ||
files.forEach(function(file,key){ | ||
var fileName = file.replace('/index.js','') | ||
.replace('.js','') | ||
.replace('endpoints/','') | ||
.replace('/','.'), | ||
requiredData = require('../'+file); | ||
register(fileName,requiredData); | ||
}) | ||
//Setup the endpoint via the setup function | ||
require('../'+file).setup(); | ||
}); | ||
} | ||
|
||
}); | ||
|
||
//Register endpoins that do not have file associated. | ||
register('phone',null); | ||
register('help_out',null); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
exports['check-globals'] = function (test) { | ||
var server = require('../server.js'); | ||
test.ok(server.moment,'Moment.js module not loaded properly'); | ||
test.done(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
exports['check-globals'] = function (test) { | ||
var server = require('../server.js'); | ||
test.ok(server.moment); | ||
test.done(); | ||
}; |