Skip to content

Commit

Permalink
Added docker support, made config dynamic (#108)
Browse files Browse the repository at this point in the history
* Made config.json dynamic

* added docker support

* Fixed dockerfile npm install error

* fixed line ends

* Revert "Made config.json dynamic"

This reverts commit 5cb413b.

* 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 <[email protected]>
  • Loading branch information
dada513 and d513 authored Mar 21, 2021
1 parent cec8f17 commit 4d4b32e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -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 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
17 changes: 11 additions & 6 deletions lib/menu.js
Original file line number Diff line number Diff line change
@@ -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 () {
Expand Down
2 changes: 2 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
3 changes: 2 additions & 1 deletion webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
]
})
]
Expand Down

0 comments on commit 4d4b32e

Please sign in to comment.