Skip to content

Commit

Permalink
registry added
Browse files Browse the repository at this point in the history
  • Loading branch information
bbossola committed Sep 5, 2015
1 parent 1ce4f1a commit 04d75cb
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
8 changes: 8 additions & 0 deletions registry/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "registry-microservice",
"author": "Bruno Bossola",
"private": true,
"dependencies": {
"express": "^4.13.3"
}
}
43 changes: 43 additions & 0 deletions registry/registry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
var express = require("express");  
var app = express();  

var registry = []

app.post("/:name/:port", function(request, response) {  
var name = request.params.name
var port = request.params.port
var ports = registry[name]
if (isNaN(ports)) {
ports=[]
}
ports.push(port)
registry[name] = ports

response.status(201);
response.json({
"name": name,
"ports": ports
});
});

app.get("/:name", function(request, response) {  
var name = request.params.name
var ports = registry[name]
if (isNaN(ports)) {
response.status(404);
response.json({
"name": name,
"error": "Service "+name+" not found!"
});
return;
}   

response.json({
"name": name,
"port": ports[0]
});
});

app.listen(3000, function() {                       
console.log("Registry service started on port 3000");
});

0 comments on commit 04d75cb

Please sign in to comment.