-
Notifications
You must be signed in to change notification settings - Fork 25
/
helloWorld.ts
75 lines (57 loc) · 2.18 KB
/
helloWorld.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { Response, Request } from "express";
import { Router } from "express-serve-static-core";
/*
This program and the accompanying materials are
made available under the terms of the Eclipse Public License v2.0 which accompanies
this distribution, and is available at https://www.eclipse.org/legal/epl-v20.html
SPDX-License-Identifier: EPL-2.0
Copyright Contributors to the Zowe Project.
*/
const express = require('express');
const Promise = require('bluebird');
const obfuscator = require ('zlux-shared/src/obfuscator/htmlObfuscator.js');
class HelloWorldDataservice{
private context: any;
private router: Router;
constructor(context: any){
let htmlObfuscator = new obfuscator.HtmlObfuscator();
this.context = context;
let router = express.Router();
router.use(function noteRequest(req: Request,res: Response,next: any) {
context.logger.info('Saw request, method='+req.method);
next();
});
context.addBodyParseMiddleware(router);
router.post('/',function(req: Request,res: Response) {
let messageFromClient = req.body ? req.body.messageFromClient : "<No/Empty Message Received from Client>"
let safeMessage = htmlObfuscator.findAndReplaceHTMLEntities(messageFromClient);
let responseBody = {
"_objectType": "org.zowe.zlux.sample.service.hello",
"_metaDataVersion": "1.0.0",
"requestBody": req.body,
"requestURL": req.originalUrl,
"serverResponse": `Router received
'${safeMessage}'
from client`
}
res.status(200).json(responseBody);
});
this.router = router;
}
getRouter():Router{
return this.router;
}
}
exports.helloWorldRouter = function(context): Router {
return new Promise(function(resolve, reject) {
let dataservice = new HelloWorldDataservice(context);
resolve(dataservice.getRouter());
});
}
/*
This program and the accompanying materials are
made available under the terms of the Eclipse Public License v2.0 which accompanies
this distribution, and is available at https://www.eclipse.org/legal/epl-v20.html
SPDX-License-Identifier: EPL-2.0
Copyright Contributors to the Zowe Project.
*/