Skip to content

Commit 642c03a

Browse files
authored
fix(docker): fix configuration endpoint, add configuration export (@fehmer) (monkeytypegame#6317)
- fixes /configure endpoint not working in docker image because of the missing `private` directory - adds `export configuration` button to api server configuration
1 parent 41b0215 commit 642c03a

File tree

6 files changed

+36
-4
lines changed

6 files changed

+36
-4
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ backend/dist
22
backend/__migration__
33
docker
44
backend/scripts
5+
backend/private
56
**/vitest.config.js

backend/private/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ <h1>API Server Configuration</h1>
5555
<span id="form-loader" class="loader"></span>
5656
</div>
5757
<div id="save">Save Changes</div>
58+
<div id="export">Export Configuration</div>
5859
<script src="script.js"></script>
5960
</body>
6061
</html>

backend/private/script.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,4 +281,27 @@ window.onload = async () => {
281281
saveButton.disabled = false;
282282
}, 3000);
283283
});
284+
285+
const exportButton = document.querySelector("#export");
286+
287+
exportButton.addEventListener("click", async () => {
288+
download(
289+
"backend-configuration.json",
290+
JSON.stringify({ configuration: state })
291+
);
292+
});
284293
};
294+
295+
function download(filename, text) {
296+
let element = document.createElement("a");
297+
element.setAttribute(
298+
"href",
299+
"data:text/plain;charset=utf-8," + encodeURIComponent(text)
300+
);
301+
element.setAttribute("download", filename);
302+
303+
element.style.display = "none";
304+
document.body.appendChild(element);
305+
element.click();
306+
document.body.removeChild(element);
307+
}

backend/private/style.css

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ body {
7474
background-color: #d84b4b;
7575
}
7676

77-
#save {
77+
#save,
78+
#export {
7879
position: fixed;
7980
right: 6rem;
8081
bottom: 3rem;
@@ -90,7 +91,12 @@ body {
9091
transition: 0.125s;
9192
}
9293

93-
#save:hover {
94+
#export {
95+
bottom: 9rem;
96+
}
97+
98+
#save:hover,
99+
#export:hover {
94100
background-color: var(--text-color);
95101
color: var(--bg-color);
96102
}

docker/backend/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ COPY --from=builder /prod/backend/node_modules /app/backend/node_modules
2929
COPY --from=builder /prod/backend/dist /app/backend/dist
3030
COPY --from=builder /prod/backend/email-templates /app/backend/email-templates
3131
COPY --from=builder /prod/backend/redis-scripts /app/backend/redis-scripts
32+
COPY --from=builder /prod/backend/private /app/backend/private
3233

3334
## to build directory
3435
WORKDIR /app/backend/dist

docs/SELF_HOSTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ If you don't want to update this file manually you can
168168

169169
- open the backend url in your browser, e.g. `http://localhost:5005/configure/`
170170
- adjust the settings and click `Save Changes`
171-
- open the configuration in your browser, e.g. `http://localhost:5005/configuration`
172-
- copy everything from `data` into the `backend-configuration.json` file.
171+
- click `Export Configuration`
172+
- save the file as `backend-configuration.json`, overwriting the existing one.
173173

174174
Example output from `http://localhost:5005/configuration`:
175175
```json

0 commit comments

Comments
 (0)