From 6798e7b09369a4e87be6ecd09decf9366f2799d2 Mon Sep 17 00:00:00 2001 From: zqn <15167104183@163.com> Date: Thu, 7 Jan 2021 18:37:22 +0800 Subject: [PATCH] get ws addr --- app/controller/v1/example.js | 11 +++++++++++ app/router/example.js | 2 ++ app/service/socket.js | 6 ++++++ 3 files changed, 19 insertions(+) diff --git a/app/controller/v1/example.js b/app/controller/v1/example.js index 8195a1e..3c05ce8 100644 --- a/app/controller/v1/example.js +++ b/app/controller/v1/example.js @@ -64,6 +64,17 @@ class ExampleController extends BaseController { self.sendData(uploadRes); } + + async getWsUrl() { + const self = this; + const { service } = this; + const data = {}; + + const addr = await service.socket.getWsUrl(); + data.url = addr; + + self.sendSuccess(data); + } } module.exports = ExampleController; diff --git a/app/router/example.js b/app/router/example.js index 88842b8..6e6bfb8 100644 --- a/app/router/example.js +++ b/app/router/example.js @@ -9,4 +9,6 @@ module.exports = app => { router.post('/api/v1/example/openLocalDir', controller.v1.example.openLocalDir); // upload file router.post('/api/v1/example/uploadFile', controller.v1.example.uploadFile); + // get ws url + router.post('/api/v1/example/getWsUrl', controller.v1.example.getWsUrl); }; \ No newline at end of file diff --git a/app/service/socket.js b/app/service/socket.js index ad2b944..f0e1a33 100644 --- a/app/service/socket.js +++ b/app/service/socket.js @@ -25,6 +25,12 @@ class SocketService extends BaseService { }); } + async getWsUrl () { + const port = this.service.storage.getElectronIPCPort(); + const url = 'http://localhost:' + port; + + return url; + } } module.exports = SocketService;