123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- <!DOCTYPE html>
- <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta charset="utf-8" />
- <title>Sers-JsStation</title>
- <script src="sers.servicestation.min.js"></script>
- <script>
- var serviceStation = new sers.ServiceStation();
- //设置websocket host 地址 demo: "ws://127.0.0.1:4503"
- //serviceStation.org.setHost("ws://127.0.0.1:4503");
- serviceStation.org.setHost('ws://' + location.hostname+':4503');
-
- //连接秘钥,用以验证连接安全性。服务端和客户端必须一致
- serviceStation.org.secretKey = "SersCL";
- /*
- user_ApiNode demo:
- //onInvoke: function(requestData_bytes,rpcData_object,reply_rpcData_object){}
- {
- route: '/JsStation/api1', httpMethod: 'GET', apiName: 'js作为服务站点',
- onInvoke: function (requestData_bytes, rpcData, reply_rpcData) {
- var request_string = vit.bytesToString(requestData_bytes);
- var replyData = {
- success: true,
- data:
- {
- request_string: request_string,
- _: Math.random()
- }
- };
- return vit.objectSerializeToBytes(replyData);
- }
- }
- */
- vit.logger.onmessage = function (msg) {
- txt_log.value = txt_log.value + '\n' + msg;
- txt_log.scrollTop = txt_log.scrollHeight;
- };
- function reloadApiNode() {
- try {
- vit.logger.info('加载api...');
- var str_apiNodes = txt_apiNodes.value;
- var user_apiNodes = eval('(' + str_apiNodes + ')');
- serviceStation.localApiService.clearApiNodes();
- for (var t in user_apiNodes) {
- var item = user_apiNodes[t];
- serviceStation.localApiService.addSimpleApiNode(item.route, item.httpMethod.toUpperCase(), item.apiName, item.onInvoke);
- }
- vit.logger.info('api已加载,数量:' + user_apiNodes.length);
- } catch (e) {
- vit.logger.error(e);
- }
- }
- function startService() {
- try {
- serviceStation.start();
- } catch (e) {
- vit.logger.error(e);
- }
- }
- function stopService() {
- try {
- serviceStation.stop();
- } catch (e) {
- vit.logger.error(e);
- }
- }
- </script>
- </head>
- <body>
- <h1>Sers-JsStation</h1>
- <div>
- <textarea type="text" id="txt_log" rows="10" cols="200"></textarea>
- <br /><input type="button" onclick="reloadApiNode()" value="加载api" />
- <input type="button" onclick="startService()" value="启动服务" />
- <input type="button" onclick="stopService()" value="关闭服务" /><br />
- <textarea type="text" id="txt_apiNodes" rows="40" cols="200">
- [
- {
- route: '/JsStation/api1', httpMethod: 'GET', apiName: 'js作为服务站点',
- onInvoke: function (requestData_bytes, rpcData, reply_rpcData) {
- var request_string = vit.bytesToString(requestData_bytes);
- vit.logger.info('[api调用] request:' + request_string );
- var replyData = {
- success: true,
- data:
- {
- request_string: request_string,
- _: Math.random()
- }
- };
- return vit.objectSerializeToBytes(replyData);
- }
- }
- ]
- </textarea>
- </div>
- </body>
- </html>
|