-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #504 from garden-io/simple-project-node-service
docs(examples): add node-service back to simple-project
- Loading branch information
Showing
7 changed files
with
109 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules | ||
Dockerfile | ||
garden.yml | ||
app.yaml |
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,12 @@ | ||
FROM node:9-alpine | ||
|
||
ENV PORT=8080 | ||
EXPOSE ${PORT} | ||
WORKDIR /app | ||
|
||
ADD package.json /app | ||
RUN npm install | ||
|
||
ADD . /app | ||
|
||
CMD ["npm", "start"] |
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,27 @@ | ||
const express = require('express'); | ||
const request = require('request-promise') | ||
const app = express(); | ||
|
||
// Unless configured otherwise, the hostname is simply the service name | ||
const goServiceEndpoint = `http://go-service/hello-go`; | ||
|
||
app.get('/hello-node', (req, res) => res.send('Hello from Node service!')); | ||
|
||
app.get('/call-go-service', (req, res) => { | ||
// Query the go-service and return the response | ||
request.get(goServiceEndpoint) | ||
.then(message => { | ||
res.json({ | ||
message, | ||
}) | ||
}) | ||
.catch((err) => { | ||
res.statusCode = 500 | ||
res.json({ | ||
error: err, | ||
message: "Unable to reach service at " + goServiceEndpoint, | ||
}) | ||
}); | ||
}); | ||
|
||
module.exports = { app } |
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,24 @@ | ||
module: | ||
name: node-service | ||
description: Node service container | ||
type: container | ||
services: | ||
- name: node-service | ||
command: [npm, start] | ||
ports: | ||
- name: http | ||
containerPort: 8080 | ||
ingresses: | ||
- path: /hello-node | ||
port: http | ||
- path: /call-go-service | ||
port: http | ||
dependencies: | ||
- go-service | ||
tests: | ||
- name: unit | ||
args: [npm, test] | ||
- name: integ | ||
args: [npm, run, integ] | ||
dependencies: | ||
- go-service |
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,3 @@ | ||
const { app } = require('./app'); | ||
|
||
app.listen(process.env.PORT, '0.0.0.0', () => console.log('Node service started')); |
22 changes: 22 additions & 0 deletions
22
examples/simple-project/services/node-service/package.json
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,22 @@ | ||
{ | ||
"name": "node-service", | ||
"version": "1.0.0", | ||
"description": "Simple Node.js docker service", | ||
"main": "main.js", | ||
"scripts": { | ||
"start": "node main.js", | ||
"test": "echo OK", | ||
"integ": "node_modules/mocha/bin/mocha test/integ.js" | ||
}, | ||
"author": "garden.io <[email protected]>", | ||
"license": "ISC", | ||
"dependencies": { | ||
"express": "^4.16.2", | ||
"request": "^2.83.0", | ||
"request-promise": "^4.2.2" | ||
}, | ||
"devDependencies": { | ||
"mocha": "^5.1.1", | ||
"supertest": "^3.0.0" | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
examples/simple-project/services/node-service/test/integ.js
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,17 @@ | ||
const supertest = require("supertest") | ||
const { app } = require("../app") | ||
|
||
describe('GET /call-go-service', () => { | ||
const agent = supertest.agent(app) | ||
|
||
it('should respond with a message from go-service', (done) => { | ||
agent | ||
.get("/call-go-service") | ||
.expect(200, { message: "Hello from Go!" }) | ||
.end((err) => { | ||
if (err) return done(err) | ||
done() | ||
}) | ||
}) | ||
}) | ||
|