Updated ES6 example.

Do some bugfixes
Added eslint global var for react gg ez
This commit is contained in:
Michael Bykovski 2017-07-25 18:48:07 +02:00
parent 91eef91b6b
commit a6fe285656
2 changed files with 32 additions and 22 deletions

View File

@ -1,3 +1,5 @@
/*global webserver*/
import UniversalRouter from 'universal-router';
import Request from "./Request";
import Response from "./Response";
@ -10,6 +12,8 @@ export default class AppServer {
this.webserver = webserver;
this.routes = [];
this.onRequest = this.onRequest.bind(this);
this.initWebserver();
this.initRouter();
}
@ -36,10 +40,10 @@ export default class AppServer {
let requestObject = new Request(
request.requestId,
request.method,
request.path,
request.query,
request.body,
request.headers
request.headers,
request.path,
request.query
);
let responseObject = new Response(
@ -48,7 +52,7 @@ export default class AppServer {
);
this.router.resolve(
requestObject.url
requestObject.path
).then(
// callback is a function
(callback) => {

View File

@ -1,5 +1,5 @@
export default class Response {
constructor(
webserver,
requestId,
@ -44,7 +44,13 @@ export default class Response {
return this.status(200).send();
}
setHeader(key, value) {
this.headers[key] = value;
return this;
}
json(data) {
this.setHeader('Content-Type', 'application/json');
this.body = JSON.stringify(data);
return this;
}