Skip to content

Commit ba8ae43

Browse files
committed
fix: config now correctly applies when no valid env or config.json given
1 parent 419dcd2 commit ba8ae43

8 files changed

Lines changed: 38 additions & 26 deletions

File tree

.env.development.local.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
VUE_APP_API=http://fluidd.local
2+
VUE_APP_SOCKET=ws://fluidd.local/websocket

.env.local.example

Lines changed: 0 additions & 2 deletions
This file was deleted.

.github/CONTRIBUTING.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ $ npm install
77
88
# Configure environment.
99
$ cd fluidd
10-
$ cp .env.local.example .env.local
10+
11+
# Copy local dev environment file, and edit it to suite your requirements.
12+
$ cp .env.development.local.example .env.development.local
13+
$ vim .env.development.local
1114
1215
# Compile and serve for development.
1316
$ npm start

public/config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"apiUrl": "//localhost",
3-
"socketUrl": "ws://localhost/websocket"
2+
"apiUrl": "",
3+
"socketUrl": ""
44
}

src/components/cards/WebCamCard.vue

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/main.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,35 @@ Vue.use(FiltersPlugin)
1919
// Load API configuration
2020
// If we're in a local development environment,
2121
// then we should load the env variables instead of the
22-
// config.json
22+
// config.json. config.json can also be used to override
23+
// the default host for API and Websockets, if required.
2324
const promise = new Promise<ApiConfig>((resolve, reject) => {
2425
if (process.env.VUE_APP_API && process.env.VUE_APP_SOCKET) {
26+
console.debug('API Config from ENV', process.env)
2527
resolve({ apiUrl: process.env.VUE_APP_API, socketUrl: process.env.VUE_APP_SOCKET })
2628
} else {
2729
fetch('/config.json', { cache: 'no-store' })
28-
.then(res => res.json())
30+
.then(res => (res.ok) ? res.json() : undefined)
31+
.then(res => {
32+
if (
33+
res &&
34+
res.apiUrl &&
35+
res.socketUrl &&
36+
res.apiUrl !== '' &&
37+
res.socketUrl !== ''
38+
) {
39+
console.debug('API Config from JSON', res)
40+
return res
41+
} else {
42+
const wsProtocol = document.location.protocol === 'https:' ? 'wss://' : 'ws://'
43+
const r = {
44+
apiUrl: '//' + window.location.host,
45+
socketUrl: wsProtocol + window.location.host + '/websocket'
46+
}
47+
console.debug('API Config from window.location', r)
48+
return r
49+
}
50+
})
2951
.then(resolve)
3052
.catch(reject)
3153
}
@@ -36,7 +58,7 @@ promise
3658
// Commit the api configuration to our store.
3759
store.commit('config/onInitApiConfig', apiConfig)
3860
return fetch(apiConfig.apiUrl + '/server/files/config/' + Globals.SETTINGS_FILENAME, { cache: 'no-store' })
39-
.then(res => (!res.ok) ? undefined : res.json())
61+
.then(res => (res.ok) ? res.json() : undefined)
4062
.then((fileConfig) => {
4163
// Init the store. This should include any GUI settings we've loaded from moonraker.
4264
return store.dispatch('init', fileConfig).then(() => {

src/views/Dashboard.vue

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,14 @@ import ToolsCard from '@/components/cards/ToolsCard.vue'
2020
import ToolheadCard from '@/components/cards/ToolheadCard.vue'
2121
import TerminalCard from '@/components/cards/TerminalCard.vue'
2222
import TemperatureCard from '@/components/cards/TemperatureCard.vue'
23-
import WebCamCard from '@/components/cards/WebCamCard.vue'
2423
2524
@Component({
2625
components: {
2726
StatusCard,
2827
ToolsCard,
2928
ToolheadCard,
3029
TerminalCard,
31-
TemperatureCard,
32-
WebCamCard
30+
TemperatureCard
3331
}
3432
})
3533
export default class Dashboard extends Vue {}

todo.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Next Up
44
- move to mdi svg icons, and reduce overall size
5+
- add custompios image
6+
- figure out a best approach for nginx
7+
- setup discord?
8+
-
59

610
## Known Bugs:
711
- multi line gcodes not having a Send: prefix after the first line

0 commit comments

Comments
 (0)