a simplest-possible mbtiles-based http/2 vector tile server
$ git clone git@github.com:hfu/tile-block.git
$ cd tile-block
$ openssl genrsa -des3 -passout pass:tile-block -out private.key 2048
$ openssl rsa -in private.key -pubout -out public.key -passin pass:tile-block
$ openssl req -new -key private.key -out server.csr
$ openssl x509 -req -days 365 -signkey private.key < server.csr > server.crt
$ npm install
$ mkdir mbtiles
$ cp /somedirectory/somewhere.mbtiles mbtiles
$ cp -r htdocs/washington htdocs/somewhere
$ vi htdocs/somewhere/index.html
$ vi htdocs/somewhere/style.json
$ node tile-block
$ open https://localhost:3776/somewhere/
You can change the port number by editing config/default.hjson. Yet you can also change the port number by the command line parameter. That will override the config settiong.
$ node tile-block 9999 # this will run the server at port 9999 regardless the config.
- to serve vector tiles from mbtiles and to host related static files.
- basically for development or evaluation; number of potential users < 1000.
- to perform moderately; faster than http serving static tiles on CIFS.
- The main program is tile-block.js.
- tile-block.js talks http/2. As in 'how to use', you need to have private.key and server.crt. Otherwise you can modify tile-block.js to use plain http. See commented part of tile-block.js.
- tile-block.js scans mbtiles files under mbtiles directory, establishng read-only connection to them.
- tile-block.js serves vector tiles from /zxy/{t}/{z}/{x}/{y} where {t} is the filename of the mbtiles file e.g., tiles from mbtiles/somewhere.mbtiles will be served through /zxy/somewhere/{z}/{x}/{y}. There is no extension used.
- Vector tiles are served gzipped with Content-Encoding: gzip, without checking Accept-Encoding.
- Static files under htdocs directory are served under /. The intent of this is to serve index.html, style.json and other related files so that we will not face CORS issues.
- For everything including bugs, please refer to tile-block.js.
You can work with the certificate from Let's Encrypt like the following.
spdy.createServer({
key: fs.readFileSync('/etc/letsencrypt/live/vectortiles.xyz/privkey.pem'),
cert: fs.readFileSync('/etc/letsencrypt/live/vectortiles.xyz/fullchain.pem'),
ca: fs.readFileSync('/etc/letsencrypt/live/vectortiles.xyz/chain.pem')
}, app).listen(port, () => { })
forks, issues, pull requests are welcome!