diff --git a/Dockerfile b/Dockerfile index 490749d..4bc76b7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,8 @@ FROM node:10-stretch ENV NODE_ENV="production" +ENV CHOKIDAR_USEPOLLING=1 +ENV CHOKIDAR_INTERVAL=500 VOLUME /data WORKDIR /data EXPOSE 80 diff --git a/Dockerfile_light b/Dockerfile_light index 3312543..c5df16f 100644 --- a/Dockerfile_light +++ b/Dockerfile_light @@ -1,6 +1,8 @@ FROM node:10-stretch ENV NODE_ENV="production" +ENV CHOKIDAR_USEPOLLING=1 +ENV CHOKIDAR_INTERVAL=500 EXPOSE 80 VOLUME /data WORKDIR /data diff --git a/package.json b/package.json index 5e6cd4f..0843589 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "@mapbox/vector-tile": "1.3.1", "advanced-pool": "0.3.3", "canvas": "2.6.1", + "chokidar": "3.3.1", "clone": "2.1.2", "color": "3.1.2", "commander": "4.0.1", @@ -34,7 +35,6 @@ "handlebars": "4.5.3", "http-shutdown": "1.2.1", "morgan": "1.9.1", - "node-watch": "0.6.3", "pbf": "3.2.1", "proj4": "2.6.0", "request": "2.88.0", diff --git a/src/server.js b/src/server.js index 8e0ff81..656e01c 100644 --- a/src/server.js +++ b/src/server.js @@ -7,6 +7,7 @@ process.env.UV_THREADPOOL_SIZE = const fs = require('fs'); const path = require('path'); +const chokidar = require('chokidar'); const clone = require('clone'); const cors = require('cors'); const enableShutdown = require('http-shutdown'); @@ -14,7 +15,6 @@ const express = require('express'); const handlebars = require('handlebars'); const mercator = new (require('@mapbox/sphericalmercator'))(); const morgan = require('morgan'); -const watch = require('node-watch'); const packageJson = require('../package'); const serve_font = require('./serve_font'); @@ -217,20 +217,24 @@ function start(opts) { } }); - watch(options.paths.styles, - { persistent: false, filter: /\.json$/ }, + const watcher = chokidar.watch(path.join(options.paths.styles, '*.json'), + { + }); + watcher.on('all', (eventType, filename) => { - let id = path.basename(filename, '.json'); - console.log(`Style "${id}" changed, updating...`); + if (filename) { + let id = path.basename(filename, '.json'); + console.log(`Style "${id}" changed, updating...`); - serve_style.remove(serving.styles, id); - serve_rendered.remove(serving.rendered, id); + serve_style.remove(serving.styles, id); + serve_rendered.remove(serving.rendered, id); - if (eventType == "update") { - let item = { - style: filename - }; - addStyle(id, item, false, false); + if (eventType == "add" || eventType == "change") { + let item = { + style: filename + }; + addStyle(id, item, false, false); + } } }); }