From ec827bbea4673b4617a4292a4304e6330dc533ce Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Tue, 14 Apr 2020 13:34:32 +0200 Subject: [PATCH] add nginx config in README --- README.md | 68 +++++++++++++++++++++++++++--- src/inputs/SettingsMacroSwitch.vue | 8 ++-- src/main.js | 48 ++++++++++----------- src/store/index.js | 2 +- 4 files changed, 89 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index afcddd46..cc462e58 100644 --- a/README.md +++ b/README.md @@ -67,13 +67,14 @@ gcode: BASE_RESUME ``` -## Installation lighttpd +## Installation lighttpd & haproxy ```bash -sudo apt install lighttpd +sudo apt install lighttpd haproxy ``` edit configfile `/etc/lighttpd/lighttpd.conf` and edit following lines: ``` server.document-root = "/home/pi/kwc" +server.bind = "127.0.0.1" server.port = 81 ``` @@ -81,11 +82,6 @@ server.port = 81 sudo usermod -a -G www-data pi ``` -## Installation haproxy -haproxy is necessary to use port 80. - -`sudo apt install haproxy` - add following lines at the end of `/etc/haproxy/haproxy.cfg`: ``` frontend public @@ -121,6 +117,64 @@ backend websocket all comments are for webcam support. You can install MJPEG-Streamer with this [tutorial](https://github.com/cncjs/cncjs/wiki/Setup-Guide:-Raspberry-Pi-%7C-MJPEG-Streamer-Install-&-Setup-&-FFMpeg-Recording). +## Installation nginx +```bash +sudo apt install nginx +``` +create configfile `/etc/nginx/sites-available/kwc`: +``` +map $http_upgrade $connection_upgrade { + default upgrade; + '' close; +} + +upstream apiserver { + #edit your api port here + server 127.0.0.1:8080; +} + +server { + listen 80 default_server; + listen [::]:80 default_server; + + access_log /var/log/nginx/kwc-access.log; + error_log /var/log/nginx/kwc-error.log; + + #web_path from kwc static files + root /home/pi/kwc; + + index index.html; + + server_name _; + + location / { + # First attempt to serve request as file, then + # as directory, then fall back to displaying a 404. + try_files $uri $uri/ =404; + } + + location /printer { + #edit here your klipper API-port + proxy_pass http://apiserver/printer; + } + + location /websocket { + proxy_pass http://apiserver/websocket; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $connection_upgrade; + proxy_set_header Host $host; + } +} +``` + +change api port & root path. + +```bash +sudo rm /etc/nginx/sites-enabled/default +sudo ln -s /etc/nginx/sites-available/kwc /etc/nginx/sites-enabled/ +sudo service nginx restart +``` ## Update KWC to V0.0.7 ``` diff --git a/src/inputs/SettingsMacroSwitch.vue b/src/inputs/SettingsMacroSwitch.vue index fb7d9887..42b6750d 100644 --- a/src/inputs/SettingsMacroSwitch.vue +++ b/src/inputs/SettingsMacroSwitch.vue @@ -29,18 +29,18 @@ methods: { setValue() { if (this.value) { - let index = this.hiddenMacros.indexOf(this.name); + let index = this.hiddenMacros.indexOf(this.name.toUpperCase()); if (index > -1) this.hiddenMacros.splice(index, 1); - } else this.hiddenMacros.push(this.name); + } else this.hiddenMacros.push(this.name.toUpperCase()); } }, watch: { hiddenMacros: function() { - this.value = !this.hiddenMacros.includes(this.name); + this.value = !this.hiddenMacros.includes(this.name.toUpperCase()); } }, created() { - this.value = !this.hiddenMacros.includes(this.name); + this.value = !this.hiddenMacros.includes(this.name.toUpperCase()); } } \ No newline at end of file diff --git a/src/main.js b/src/main.js index ed8efe24..6252a3f9 100644 --- a/src/main.js +++ b/src/main.js @@ -20,29 +20,27 @@ Vue.http.headers.common['Access-Control-Allow-Methods'] = 'POST, GET, PUT, OPTIO Vue.component('vue-headful', vueHeadful); -fetch('/config.json').then(res => res.json()).then(file => { - store.commit('setSettings', file); +fetch('/config.json').then(res => res.json()) + .then(file => { + store.commit('setSettings', file); + Vue.use(JRPCWS, 'ws://' + store.state.socket.hostname + ':' + store.state.socket.port + '/websocket', { + store: store, + reconnectEnabled: true, + reconnectInterval: store.state.socket.reconnectInterval, + reconnectAttempts: store.state.socket.reconnectAttempts, + }); - Vue.use(JRPCWS, 'ws://' + store.state.socket.hostname + ':' + store.state.socket.port + '/websocket', { - store: store, - reconnectEnabled: true, - reconnectInterval: store.state.socket.reconnectInterval, - reconnectAttempts: store.state.socket.reconnectAttempts, - }); - - new Vue({ - data(){ - return file - }, - vuetify, - router, - store, - render: h => h(App) - }).$mount('#app') -}).catch((error) => { - let p = document.createElement("p"); - let content = document.createTextNode("config.json not found or cannot be decoded!"); - p.appendChild(content); - document.getElementById('app').append(p); - window.console.error('Error:', error); -}); \ No newline at end of file + new Vue({ + vuetify, + router, + store, + render: h => h(App) + }).$mount('#app') + }) + .catch((error) => { + let p = document.createElement("p"); + let content = document.createTextNode("config.json not found or cannot be decoded!"); + p.appendChild(content); + document.getElementById('app').append(p); + window.console.error('Error:', error); + }); \ No newline at end of file diff --git a/src/store/index.js b/src/store/index.js index b98d155f..c7cb46d7 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -12,7 +12,7 @@ export default new Vuex.Store({ state: { socket: { hostname: window.location.hostname, - port: 8080, + port: window.location.port, reconnectInterval: 3000, reconnectAttempts: 1000, isConnected: false,