Skip to content

Commit

Permalink
Umgeschrieben auf moleculer-runner - Services als reine JSON-Konfigur…
Browse files Browse the repository at this point in the history
…ation ohne Boilerplate
  • Loading branch information
Michael (at Home) committed Nov 21, 2019
1 parent d584d58 commit 161a1fd
Show file tree
Hide file tree
Showing 7 changed files with 701 additions and 52 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ Entpacke und starte ```nats-server```.
Dann:

```
yarn start
yarn dev
```

für Hotloading Services!

## Im Browser:

```
Expand Down
2 changes: 0 additions & 2 deletions index.js

This file was deleted.

12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
"name": "obstladen",
"license": "MIT",
"dependencies": {
"moleculer": "^0.13.9",
"moleculer-web": "^0.8.5",
"nats": "^1.2.10"
"moleculer": "^0.13.9",
"moleculer-repl": "^0.6.1",
"moleculer-web": "^0.8.5",
"nats": "^1.2.10"
},
"scripts": {
"start": "node index.js"
"start": "moleculer-runner --instances=4 services",
"dev": "moleculer-runner --repl --hot services"
}
}
}
17 changes: 4 additions & 13 deletions products.js → services/products.service.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
const { ServiceBroker } = require("moleculer");

// Define nodeID and set the communication bus
const node = new ServiceBroker({
nodeID: "node-2",
transporter: "NATS"
});

const obst = [
{ name: "Apples", price: 5 },
{ name: "Oranges", price: 3 },
{ name: "Bananas", price: 2 }
{ name: "Bananas", price: 2 },
{ name: "Papaya", price: 10 },
]

// Create the "products" service
node.createService({
module.exports = {
// Define service name
name: "products",

Expand All @@ -26,6 +18,5 @@ node.createService({
return obst[ctx.params.index]
}
}
});
}

module.exports = node;
18 changes: 18 additions & 0 deletions services/storefront.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const APIGateway = require("moleculer-web")

module.exports = {
// Define service name
name: "storefront",
// Load the HTTP server
mixins: [APIGateway],
settings: {
routes: [
{
aliases: {
"GET /products": "products.listProducts",
"GET /products/:index": "products.getProduct"
}
}
]
}
}
28 changes: 0 additions & 28 deletions storefront.js

This file was deleted.

Loading

0 comments on commit 161a1fd

Please sign in to comment.