From 4d4b32e8de8b73f881bf3b7b8e1190a474102c81 Mon Sep 17 00:00:00 2001 From: dada513 Date: Sun, 21 Mar 2021 17:14:14 +0100 Subject: [PATCH] Added docker support, made config dynamic (#108) * Made config.json dynamic * added docker support * Fixed dockerfile npm install error * fixed line ends * Revert "Made config.json dynamic" This reverts commit 5cb413b9aabfcec98335bf6ab6b589c2bc29c3e4. * config.json is now loaded dynamically * Made dynamic config work on github page * config is now dynamically copied * removed sync-request dependency Co-authored-by: d513 --- .dockerignore | 5 +++++ Dockerfile | 9 +++++++++ lib/menu.js | 17 +++++++++++------ server.js | 2 ++ webpack.common.js | 3 ++- 5 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..285d130 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +# we dont want default config to be loaded in the dockerfile, but rather using a volume +config.json +# build stuff +node_modules +public \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..aa9eb3d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM node:14-alpine +# Without git installing the npm packages fails +RUN apk add git +RUN mkdir /app +WORKDIR /app +COPY . /app +RUN npm install +RUN npm run build +ENTRYPOINT ["npm", "run", "prod-start"] diff --git a/lib/menu.js b/lib/menu.js index 872939d..7a879a3 100644 --- a/lib/menu.js +++ b/lib/menu.js @@ -1,17 +1,22 @@ const { LitElement, html, css } = require('lit-element') -const config = require('../config.json') require('./github_link') - +/* global fetch */ class PrismarineMenu extends LitElement { constructor () { super() - this.server = config.defaultHost - this.serverport = config.defaultHostPort ?? 25565 - this.proxy = config.defaultProxy - this.proxyport = !config.defaultProxy && !config.defaultProxyPort ? '' : config.defaultProxyPort ?? 443 + this.server = '' + this.serverport = 25565 + this.proxy = '' + this.proxyport = '' this.username = window.localStorage.getItem('username') ?? 'pviewer' + (Math.floor(Math.random() * 1000)) this.password = '' + fetch('config.json').then(res => res.json()).then(config => { + this.server = config.defaultHost + this.serverport = config.defaultHostPort ?? 25565 + this.proxy = config.defaultProxy + this.proxyport = !config.defaultProxy && !config.defaultProxyPort ? '' : config.defaultProxyPort ?? 443 + }) } static get properties () { diff --git a/server.js b/server.js index d819e48..6581a6b 100644 --- a/server.js +++ b/server.js @@ -8,6 +8,8 @@ const path = require('path') // Create our app const app = express() +app.get('/config.json', (_, res) => res.sendFile(path.join(__dirname, 'config.json'))) + app.use(compression()) app.use(netApi({ allowOrigin: '*' })) if (process.argv[3] === 'dev') { diff --git a/webpack.common.js b/webpack.common.js index c968010..8ec6f04 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -73,7 +73,8 @@ const config = { { from: path.join(__dirname, '/node_modules/prismarine-viewer/public/worker.js'), to: './' }, { from: path.join(__dirname, '/node_modules/prismarine-viewer/public/supportedVersions.json'), to: './' }, { from: path.join(__dirname, 'assets/'), to: './' }, - { from: path.join(__dirname, 'extra-textures/'), to: './extra-textures/' } + { from: path.join(__dirname, 'extra-textures/'), to: './extra-textures/' }, + { from: path.join(__dirname, 'config.json'), to: './config.json' } ] }) ]