From cb4d63c6bea86e0f1c97787e5d28ec5c695539d2 Mon Sep 17 00:00:00 2001 From: Sylvain Gay Date: Tue, 12 Sep 2023 11:44:32 +0200 Subject: [PATCH] legacy replaceAll --- traque.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/traque.js b/traque.js index 6d787af..3ed1320 100644 --- a/traque.js +++ b/traque.js @@ -52,6 +52,15 @@ const option = { cert: fs.readFileSync(config.cert) }; +function replaceAll_legacy(data, pattern, replacement){ + var replacing = data.replace(pattern, replacement); + while(replacing != data){ + data = replacing; + replacing = data.replace(pattern, replacement); + } + return data; +} + // The server var server = https.createServer(option, function(req, res){ var q = url.parse(req.url, true); @@ -73,7 +82,7 @@ var server = https.createServer(option, function(req, res){ throw new Error("where " + end_path + " is !?"); res.writeHead(200, {'Content-Type': 'text/html'}); - res.write(data.replaceAll("%ID", id).replaceAll("%GPSLOG", gpslog)); + res.write(replaceAll_legacy(replaceAll_legacy(data, "%GPSLOG", gpslog), "%ID", id)); return res.end(); }); }