Skip to content

Commit

Permalink
add cors example
Browse files Browse the repository at this point in the history
  • Loading branch information
icebob committed Sep 1, 2021
1 parent 6494462 commit 9d723d8
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions examples/cors/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"use strict";

/**
*
*/

const { ServiceBroker } = require("moleculer");
const ApiService = require("../../index");

// Create broker
const broker = new ServiceBroker();

// Load other services
broker.createService({
name: "greeter",
actions: {
welcome(ctx) {
return { response: `Hello ${ctx.params.name || "Anonymous"}` };
}
}
});

// Load API Gateway
broker.createService({
name: "api",
mixins: [ApiService],

settings: {
cors: true,
routes: [
{
path: "/api1",

aliases: {
"welcome": {
method: "POST",
fullPath: "/welcome",
action: "greeter.welcome"
}
},
},
{
path: "/api2",

aliases: {
"welcome": {
method: "POST",
fullPath: "/api2/welcome",
action: "greeter.welcome"
}
},
}
]
}
});

// Start server
broker.start().then(() => broker.repl());

0 comments on commit 9d723d8

Please sign in to comment.