The nodeJs way of deploying webservices
npm install roadie
this.inherited().)
javascript
"use strict";
var $r = require("roadie");
// create routes by providing a file name containing the routes
// or by adding them inline
var routes = [
"routing.json",
{
"[GET,POST]/statics/*": "static.js",
"[GET]/query/": function(ctx) {
// echo the parameters in the search query of the URL
ctx.response.data(ctx.request.queryParams);
ctx.response.send();
},
},
];
// HTTP server with (optional) config server
var server = new $r.Server({
port: 8080,
webserviceDir: "webservices/",
root: __dirname,
});
var config = new $r.ConfigServer(server, { port: 4242 });
// Add the routes to the server
server.addRoutes(routes);
console.log(
"Go to http://localhost:8080/test/{anything}/ or http://localhost:8080/statics/test.html",
);
server.start();
config.start();
`
routing.json
`json
{
"[GET]/test/{id}/": "test.js:gId",
"[GET]/test/hallo/": "test.js:hallo"
}
`
webservices/test.js
`javascript
"use strict";
var $r = require("roadie");
module.exports = $r.WebService.extend({
// Simple webservice returning "HAAY!"
hallo: function() {
this.ctx.response.data("HAAY!");
this.ctx.response.send();
},
// Webservice which will return the parameter it got within the URL.
gId: function() {
var id = this.ctx.request.parameters.id;
this.ctx.response.data("got: " + id);
this.ctx.response.send();
},
});
``