Skip to content

Commit

Permalink
ws 端口跟随自定义
Browse files Browse the repository at this point in the history
  • Loading branch information
yhy0 committed Jan 20, 2024
1 parent e0703eb commit da912d4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion SCopilot/templates/SCopilot.html
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,8 @@ <h4 class="level mb-0">

const host = window.location.hostname;
const t = new URLSearchParams(window.location.search).get('host');
const socket = new WebSocket(`ws://${host}:9088/ws?host=${t}`);
const port = "{{ .webPort }}";
const socket = new WebSocket(`ws://${host}:${port}/ws?host=${t}`);

socket.addEventListener('message', (event) => {
var toastElList = [].slice.call(document.querySelectorAll('.toast'))
Expand Down
3 changes: 2 additions & 1 deletion SCopilot/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ <h1 class="modal-title fs-5" id="exampleModalLabel">清空所有数据</h1>
<script>
const targetListDiv = document.getElementById('targetList');
const host = window.location.hostname;
const socket = new WebSocket(`ws://${host}:9088/ws`);
const port = "{{ .webPort }}";
const socket = new WebSocket(`ws://${host}:${port}/ws`);

socket.addEventListener('message', (event) => {
const data = JSON.parse(event.data);
Expand Down
12 changes: 7 additions & 5 deletions SCopilot/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,20 @@ func Init() {

authorized.GET("/index", func(c *gin.Context) {
c.HTML(http.StatusOK, "index.html", gin.H{
"list": output.SCopilotLists,
"year": time.Now().Year(),
"webPort": conf.GlobalConfig.Passive.WebPort,
"list": output.SCopilotLists,
"year": time.Now().Year(),
})
})

authorized.GET("/SCopilot", func(c *gin.Context) {
host := c.Query("host")

c.HTML(http.StatusOK, "SCopilot.html", gin.H{
"data": output.SCopilotMessage[host],
"ipInfo": output.IPInfoList[output.SCopilotMessage[host].HostNoPort],
"year": time.Now().Year(),
"webPort": conf.GlobalConfig.Passive.WebPort,
"data": output.SCopilotMessage[host],
"ipInfo": output.IPInfoList[output.SCopilotMessage[host].HostNoPort],
"year": time.Now().Year(),
})
})

Expand Down

0 comments on commit da912d4

Please sign in to comment.