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 5cb413b9aa.

* 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 <ogoniasty513@gmail.com>
This commit is contained in:
dada513 2021-03-21 17:14:14 +01:00 committed by GitHub
parent cec8f176f1
commit 4d4b32e8de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 7 deletions

5
.dockerignore Normal file
View file

@ -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

9
Dockerfile Normal file
View file

@ -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"]

View file

@ -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 () {

View file

@ -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') {

View file

@ -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' }
]
})
]