json-server
json-server copied to clipboard
--watch does not work when running with docker-compose
I need to regenerate random data in each GET request. Since the data generation script can only be executed once during the json-server startup, I added a middleware function which opens the static data file, modifies partial data and write back to the same file. When I start up json-server on VM, the watch command seems to work and I get different data every time. However, the watch command does not seem to work when running in Docker container (specifically in docker-compose.yml) and I get the same data even the file is modified. Looks like the watch does not detect the file change and data is not reloaded. Can someone please assist?
Instead of this solution, is there a better solution? For example, is it possible to rerun data generation script after each GET request?
json-server: image: clue/json-server command: -w db.json -middlewares ./update.js -host 0.0.0.0 volumes:
- ./db.json:/data/db.json
- ./update.js:/data/update.js