Skip to content

Commit

Permalink
Use chokidar instead of node-watch to poll the files (required for do…
Browse files Browse the repository at this point in the history
…cker)
  • Loading branch information
petrsloup committed Jan 15, 2020
1 parent aa933e5 commit ea89d11
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
2 changes: 2 additions & 0 deletions 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
Expand Down
2 changes: 2 additions & 0 deletions 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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
32 changes: 18 additions & 14 deletions src/server.js
Expand Up @@ -7,14 +7,14 @@ 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');
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');
Expand Down Expand Up @@ -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...`);

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 (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);

if (eventType == "add" || eventType == "change") {
let item = {
style: filename
};
addStyle(id, item, false, false);
}
}
});
}
Expand Down

0 comments on commit ea89d11

Please sign in to comment.