Updated ES6 example.
Do some bugfixes Added eslint global var for react gg ez
This commit is contained in:
parent
91eef91b6b
commit
a6fe285656
@ -1,3 +1,5 @@
|
|||||||
|
/*global webserver*/
|
||||||
|
|
||||||
import UniversalRouter from 'universal-router';
|
import UniversalRouter from 'universal-router';
|
||||||
import Request from "./Request";
|
import Request from "./Request";
|
||||||
import Response from "./Response";
|
import Response from "./Response";
|
||||||
@ -10,6 +12,8 @@ export default class AppServer {
|
|||||||
this.webserver = webserver;
|
this.webserver = webserver;
|
||||||
this.routes = [];
|
this.routes = [];
|
||||||
|
|
||||||
|
this.onRequest = this.onRequest.bind(this);
|
||||||
|
|
||||||
this.initWebserver();
|
this.initWebserver();
|
||||||
this.initRouter();
|
this.initRouter();
|
||||||
}
|
}
|
||||||
@ -36,10 +40,10 @@ export default class AppServer {
|
|||||||
let requestObject = new Request(
|
let requestObject = new Request(
|
||||||
request.requestId,
|
request.requestId,
|
||||||
request.method,
|
request.method,
|
||||||
request.path,
|
|
||||||
request.query,
|
|
||||||
request.body,
|
request.body,
|
||||||
request.headers
|
request.headers,
|
||||||
|
request.path,
|
||||||
|
request.query
|
||||||
);
|
);
|
||||||
|
|
||||||
let responseObject = new Response(
|
let responseObject = new Response(
|
||||||
@ -48,7 +52,7 @@ export default class AppServer {
|
|||||||
);
|
);
|
||||||
|
|
||||||
this.router.resolve(
|
this.router.resolve(
|
||||||
requestObject.url
|
requestObject.path
|
||||||
).then(
|
).then(
|
||||||
// callback is a function
|
// callback is a function
|
||||||
(callback) => {
|
(callback) => {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
export default class Response {
|
export default class Response {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
webserver,
|
webserver,
|
||||||
requestId,
|
requestId,
|
||||||
@ -44,7 +44,13 @@ export default class Response {
|
|||||||
return this.status(200).send();
|
return this.status(200).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setHeader(key, value) {
|
||||||
|
this.headers[key] = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
json(data) {
|
json(data) {
|
||||||
|
this.setHeader('Content-Type', 'application/json');
|
||||||
this.body = JSON.stringify(data);
|
this.body = JSON.stringify(data);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user