From 2517b8392a2056851e30bed88f6d1528da98a61b Mon Sep 17 00:00:00 2001 From: hibobmaster <32976627+hibobmaster@users.noreply.github.com> Date: Sat, 2 Mar 2024 11:48:32 +0800 Subject: [PATCH] Fix undefined variable and add nginx conf --- frontend/src/main.js | 10 +++++----- nginx.conf | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 nginx.conf diff --git a/frontend/src/main.js b/frontend/src/main.js index 419af45..64098d9 100644 --- a/frontend/src/main.js +++ b/frontend/src/main.js @@ -43,7 +43,7 @@ let chart = new Chart( const restartBtn = document.getElementById("restart-server-btn") window.onload = function () { - fetch('http://127.0.0.1:10000/') + fetch('/api') .then(response => response.json()) .then(data => { let compose_string = ""; @@ -59,7 +59,7 @@ window.onload = function () { console.log(error); }); - fetch('http://127.0.0.1:10000/get_latency') + fetch('/api/get_latency') .then(response => response.json()) .then(data => { for (let i = 0; i < data.length; i = i + 2) { @@ -72,10 +72,10 @@ window.onload = function () { setInterval(function () { - fetch('http://127.0.0.1:10000') + fetch('/api') .then(response => response.json()) .then(data => { - compose_string = ""; + let compose_string = ""; compose_string += "当前时间: " + data.time; compose_string += "\n服务器描述: " + data.description; compose_string += "\n延迟: " + data.latency + "ms"; @@ -106,7 +106,7 @@ restartBtn.addEventListener("click", () => { onConfirm: (value) => { restartBtn.disabled = true; restartBtn.loading = true; - fetch("http://127.0.0.1:10000/restart-server", { + fetch("/api/restart-server", { method: "POST", headers: { "Accept": "application/json", diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..338192d --- /dev/null +++ b/nginx.conf @@ -0,0 +1,35 @@ +server { + listen 80; + server_name "your domain name"; + location / { + return 301 https://$host$request_uri; + } +} + +server { + listen 443 ssl http2; + server_name "your domain name"; + + # ssl related config + + root /var/www/mc_status/dist; + index index.html; + + location = /api { + proxy_pass http://127.0.0.1:10010; + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + # add_header Access-Control-Allow-Origin *; + } + + location /api/ { + proxy_pass http://127.0.0.1:10010/; + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + # add_header Access-Control-Allow-Origin *; + } +} \ No newline at end of file