Skip to content

Commit fe13b12

Browse files
committed
Removed the need to restart Nginx Proxy Manager after generating JWT key pair.
1 parent b243324 commit fe13b12

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

backend/models/token.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,23 @@
44
*/
55

66
const _ = require('lodash');
7-
const config = require('config');
87
const jwt = require('jsonwebtoken');
98
const crypto = require('crypto');
109
const error = require('../lib/error');
1110
const ALGO = 'RS256';
1211

12+
let public_key = null;
13+
let private_key = null;
14+
15+
function checkJWTKeyPair() {
16+
if (!public_key || !private_key) {
17+
let config = require('config');
18+
public_key = config.get('jwt.pub');
19+
private_key = config.get('jwt.key');
20+
}
21+
}
22+
1323
module.exports = function () {
14-
const public_key = config.get('jwt.pub');
15-
const private_key = config.get('jwt.key');
1624

1725
let token_data = {};
1826

@@ -32,6 +40,8 @@ module.exports = function () {
3240
.toString('base64')
3341
.substr(-8);
3442

43+
checkJWTKeyPair();
44+
3545
return new Promise((resolve, reject) => {
3646
jwt.sign(payload, private_key, options, (err, token) => {
3747
if (err) {
@@ -53,6 +63,7 @@ module.exports = function () {
5363
*/
5464
load: function (token) {
5565
return new Promise((resolve, reject) => {
66+
checkJWTKeyPair();
5667
try {
5768
if (!token || token === null || token === 'null') {
5869
reject(new error.AuthError('Empty token'));

backend/setup.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,8 @@ const setupJwt = () => {
5151
reject(err);
5252
} else {
5353
logger.info('Wrote JWT key pair to config file: ' + filename);
54-
55-
logger.warn('Restarting interface to apply new configuration');
56-
process.exit(0);
54+
delete require.cache[require.resolve('config')];
55+
resolve();
5756
}
5857
});
5958
} else {

0 commit comments

Comments
 (0)