Skip to content

Commit

Permalink
Merge pull request #394 from amalgam8/nodejs_ratings
Browse files Browse the repository at this point in the history
node.js implementation of ratings
  • Loading branch information
ijsnellf committed Nov 10, 2016
2 parents bf7f2e3 + a50450a commit acb2a69
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 109 deletions.
7 changes: 2 additions & 5 deletions examples/apps/bookinfo/ratings/Dockerfile
Expand Up @@ -12,10 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM python:2-onbuild
FROM node:4-onbuild

RUN mkdir -p /opt/microservices
COPY . /opt/microservices/
EXPOSE 9080
WORKDIR /opt/microservices
CMD python ratings.py 9080 http://localhost:6379
CMD node ratings.js 9080 http://localhost:6379
7 changes: 2 additions & 5 deletions examples/apps/bookinfo/ratings/Dockerfile.sidecar
Expand Up @@ -12,13 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM python:2-onbuild
FROM node:4-onbuild

RUN wget -qO- https://github.com/amalgam8/amalgam8/releases/download/v0.4.2/a8sidecar.sh | sh

RUN mkdir -p /opt/microservices
COPY . /opt/microservices/
EXPOSE 9080
WORKDIR /opt/microservices

ENTRYPOINT ["a8sidecar", "python", "ratings.py", "9080"]
ENTRYPOINT ["a8sidecar", "node", "ratings.js", "9080"]
8 changes: 8 additions & 0 deletions examples/apps/bookinfo/ratings/package.json
@@ -0,0 +1,8 @@
{
"scripts": {
"start": "node ratings.js"
},
"dependencies": {
"httpdispatcher": "1.0.0"
}
}
73 changes: 73 additions & 0 deletions examples/apps/bookinfo/ratings/ratings.js
@@ -0,0 +1,73 @@
// Copyright 2016 IBM Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

var http = require('http');
var dispatcher = require('httpdispatcher');

port = parseInt(process.argv[2]);
proxyURL = process.argv[3];

var ratingsResponse = {"Reviewer1": 5, "Reviewer2": 4}

dispatcher.onGet("/", function(req, res) {
res.writeHead(200)
res.end(
'<html>' +
'<head>' +
'<meta charset="utf-8">' +
'<meta http-equiv="X-UA-Compatible" content="IE=edge">' +
'<meta name="viewport" content="width=device-width, initial-scale=1">' +
'<!-- Latest compiled and minified CSS -->' +
'<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">' +
'<!-- Optional theme -->' +
'<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">' +
'<!-- Latest compiled and minified JavaScript -->' +
'<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>' +
'<!-- Latest compiled and minified JavaScript -->' +
'<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>' +
'</head>' +
'<title>Book ratings service</title>' +
'<body>' +
'<p><h2>Hello! This is the book ratings service. My content is</h2></p>' +
'<div>' + JSON.stringify(ratingsResponse) + '</div>' +
'</body>' +
'</html>',
{"Content-type": "text/html"})
})

dispatcher.onGet("/ratings", function(req, res) {
var json = JSON.stringify(ratingsResponse)
res.writeHead(200, {"Content-type": "application/json"})
res.end(json)
})

dispatcher.onGet("/health", function(req, res) {
res.writeHead(200, {"Content-type": "text/plain"})
res.end("Ratings is healthy")
})

function handleRequest(request, response){
try {
console.log(request.method + " " + request.url);
dispatcher.dispatch(request, response);
} catch(err) {
console.log(err);
}
}

var server = http.createServer(handleRequest);

server.listen(port, function(){
console.log("Server listening on: http://localhost:%s", port);
});
90 changes: 0 additions & 90 deletions examples/apps/bookinfo/ratings/ratings.py

This file was deleted.

8 changes: 0 additions & 8 deletions examples/apps/bookinfo/ratings/requirements.txt

This file was deleted.

1 change: 0 additions & 1 deletion examples/docker-bookinfo.yaml
Expand Up @@ -50,7 +50,6 @@ ratings-v1:
- A8_SERVICE=ratings:v1
- A8_REGISTER=true
- A8_ENDPOINT_PORT=9080
- A8_HEALTHCHECKS=http://localhost:9080/health
external_links:
- registry

Expand Down

0 comments on commit acb2a69

Please sign in to comment.