Skip to content

Commit

Permalink
Merge pull request #25 from chpicone/issue-24
Browse files Browse the repository at this point in the history
Issue 24
  • Loading branch information
DenisCarriere committed Feb 12, 2020
2 parents fc303d9 + dfaf2f8 commit e8fd53d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 19 deletions.
12 changes: 7 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ COPY . /src/
RUN mkdir -p /root/mbtiles

# Enables customized options using environment variables
ENV CACHE='/root/mbtiles'
ENV PROTOCOL='http'
ENV DOMAIN='localhost'
ENV PORT='5000'
ENV VERBOSE='true'
ENV MBTILES_SERVER_CACHE='/root/mbtiles'
ENV MBTILES_SERVER_PROTOCOL='http'
ENV MBTILES_SERVER_DOMAIN='localhost'
ENV MBTILES_SERVER_PORT='5000'
ENV MBTILES_SERVER_SSL_KEY='/root/mbtiles/server.key'
ENV MBTILES_SERVER_SSL_CERT='/root/mbtiles/server.cert'
ENV MBTILES_SERVER_VERBOSE='true'

# Run App
EXPOSE 5000
Expand Down
5 changes: 3 additions & 2 deletions bin/mbtiles-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const updateNotifier = require('update-notifier')
const pkg = require('../package.json')
const DEFAULT = require('../config')
const server = require('../')
const path = require('path')

// Update if required
updateNotifier({ pkg }).notify()
Expand Down Expand Up @@ -35,8 +36,8 @@ const port = cli.flags.port || DEFAULT.PORT
const cache = cli.flags.cache || DEFAULT.CACHE
const domain = cli.flags.domain || DEFAULT.DOMAIN
const verbose = cli.flags.verbose || DEFAULT.VERBOSE
const sslkey = cli.flags.sslkey || DEFAULT.SSL_KEY
const sslcert = cli.flags.sslcert || DEFAULT.SSL_CERT
const sslkey = cli.flags.sslkey || (DEFAULT.SSL_KEY || path.join(cache, 'server.key'))
const sslcert = cli.flags.sslcert || (DEFAULT.SSL_CERT || path.join(cache, 'server.cert'))
const watch = cli.flags.watch

// Verbose output
Expand Down
4 changes: 2 additions & 2 deletions config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const PROTOCOL = process.env.MBTILES_SERVER_PROTOCOL || 'http'
const DOMAIN = process.env.MBTILES_SERVER_DOMAIN || '127.0.0.1'
const PORT = process.env.MBTILES_SERVER_PORT || 5000
const CACHE = process.env.MBTILES_SERVER_CACHE || path.join(os.homedir(), 'mbtiles')
const SSL_KEY = process.env.MBTILES_SERVER_SSL_KEY || path.join(CACHE, 'server.key')
const SSL_CERT = process.env.MBTILES_SERVER_SSL_CERT || path.join(CACHE, 'server.cert')
const SSL_KEY = process.env.MBTILES_SERVER_SSL_KEY
const SSL_CERT = process.env.MBTILES_SERVER_SSL_CERT
const VERBOSE = process.env.MBTILES_SERVER_VERBOSE || false

module.exports = {
Expand Down
26 changes: 17 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ module.exports = function (options = {}) {
config.set('PROTOCOL', options.protocol || DEFAULT.PROTOCOL)
config.set('PORT', options.port || DEFAULT.PORT)
config.set('DOMAIN', options.domain || DEFAULT.DOMAIN)
config.set('CACHE', options.cache || DEFAULT.CACHE)
config.set('SSL_KEY', options.sslkey || DEFAULT.SSL_KEY)
config.set('SSL_CERT', options.sslcert || DEFAULT.SSL_CERT)
const cache = options.cache || DEFAULT.CACHE
const sslkey = options.sslkey || (DEFAULT.SSL_KEY || path.join(cache, 'server.key'))
const sslcert = options.sslcert || (DEFAULT.SSL_CERT || path.join(cache, 'server.cert'))
config.set('CACHE', cache)
config.set('SSL_KEY', sslkey)
config.set('SSL_CERT', sslcert)

// Settings
const app = express()
Expand All @@ -57,16 +60,18 @@ module.exports = function (options = {}) {
const port = options.port || DEFAULT.PORT
const domain = options.domain || DEFAULT.DOMAIN
const cache = options.cache || DEFAULT.CACHE
const sslkey = options.sslkey || DEFAULT.SSL_KEY
const sslcert = options.sslcert || DEFAULT.SSL_CERT
const sslkey = options.sslkey || (DEFAULT.SSL_KEY || path.join(cache, 'server.key'))
const sslcert = options.sslcert || (DEFAULT.SSL_CERT || path.join(cache, 'server.cert'))
const watch = options.watch
options = { protocol, port, domain, cache, watch }
options = { protocol, port, domain, cache, watch, sslkey, sslcert }

// Save local settings
config.set('PROTOCOL', protocol)
config.set('PORT', port)
config.set('DOMAIN', domain)
config.set('CACHE', cache)
config.set('SSL_CERT', sslcert)
config.set('SSL_KEY', sslkey)
this.cache = cache
this.watch = watch

Expand All @@ -85,9 +90,12 @@ module.exports = function (options = {}) {
if (protocol === 'http') {
server = http.createServer(app)
} else {
let options = {
key: fs.readFileSync(sslkey, 'utf8'),
cert: fs.readFileSync(sslcert, 'utf8')
let options = {}
if (fs.existsSync(sslkey) && fs.existsSync(sslcert)) {
options = {
key: fs.readFileSync(sslkey, 'utf8'),
cert: fs.readFileSync(sslcert, 'utf8')
}
}
server = https.createServer(options, app)
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mbtiles-server",
"version": "3.3.3",
"version": "3.3.4",
"description": "Provides a compatible WMTS Tile Server from MBTiles.",
"repository": {
"type": "git",
Expand Down

0 comments on commit e8fd53d

Please sign in to comment.