Merge pull request #2 from bus9001/env
Additional configuration options via environment variables
This commit is contained in:
commit
3286cc045f
11
README.md
11
README.md
|
@ -22,6 +22,13 @@ API_KEY=mykey syncthing-hooks
|
|||
|
||||
Don't forget to substitute `mykey` with your syncthing API key, which can be found in the settings in the GUI.
|
||||
|
||||
If Syncthing runs on another host or listens to a non-default port, you can specify an URL by using `ST_URL`.
|
||||
Note that this URL has to include the protocol, hostname, port and path, e.g.:
|
||||
|
||||
```
|
||||
ST_URL=http://<ip>:8384/rest/events
|
||||
```
|
||||
|
||||
It won't install itself as a daemon by default, however. In order to run it as a service, it is recommended to install [pm2](https://pm2.keymetrics.io/):
|
||||
|
||||
```sh
|
||||
|
@ -44,7 +51,9 @@ pm2 logs
|
|||
|
||||
## Hooks
|
||||
|
||||
Create a folder in your home directory called `.syncthing-hooks`. Each hook is a file with the following naming scheme:
|
||||
Create a folder in your home directory called `.syncthing-hooks`.
|
||||
A different directory can be set using `ST_HOOK_ROOT`.
|
||||
Each hook is a file with the following naming scheme:
|
||||
|
||||
`folder-name-delay`
|
||||
|
||||
|
|
5
api.js
5
api.js
|
@ -1,9 +1,10 @@
|
|||
const got = require('got');
|
||||
const { getEnvVar } = require('./env.js');
|
||||
|
||||
const fetchEvents = () =>
|
||||
got('http://localhost:8384/rest/events', {
|
||||
got(getEnvVar('ST_URL','http://localhost:8384/rest/events'), {
|
||||
headers: {
|
||||
'X-API-Key': process.env.API_KEY,
|
||||
'X-API-Key': getEnvVar('API_KEY','invalid')
|
||||
},
|
||||
}).json();
|
||||
|
||||
|
|
9
env.js
Normal file
9
env.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
module.exports = {
|
||||
getEnvVar: function (varname, defaultvalue){
|
||||
var result = process.env[varname];
|
||||
if(result!=undefined)
|
||||
return result;
|
||||
else
|
||||
return defaultvalue;
|
||||
}
|
||||
};
|
3
hooks.js
3
hooks.js
|
@ -3,8 +3,9 @@ const ms = require('ms');
|
|||
const os = require('os');
|
||||
const path = require('path');
|
||||
const { spawn } = require('child_process');
|
||||
const { getEnvVar } = require('./env.js');
|
||||
|
||||
const getHooksRoot = () => path.join(os.homedir(), '/.syncthing-hooks');
|
||||
const getHooksRoot = () => getEnvVar('ST_HOOK_ROOT', path.join(os.homedir(), '/.syncthing-hooks'))
|
||||
|
||||
const readHooksRoot = async root => {
|
||||
try {
|
||||
|
|
Loading…
Reference in a new issue