From b7e1cd362eea94ad3d4f5006e8292b6cead13036 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Thu, 9 Nov 2017 13:09:49 +0200 Subject: [PATCH] Use region.txt to id server just like php version --- .gitignore | 1 + app.js | 17 +++++++++++++++-- package.json | 6 +++--- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 8c31f95..a67c5d9 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,6 @@ .elasticbeanstalk node_modules package-lock.json +region.txt *.log .ssl/ssl.* \ No newline at end of file diff --git a/app.js b/app.js index ccd1c0f..f0bdb96 100644 --- a/app.js +++ b/app.js @@ -38,6 +38,19 @@ const cache = 604800; // cache time in seconds const cacheMin = cache; // minimum cache refresh time in seconds const cachePrivate = false; // True if cache is private +// Region file to easy identify server in CDN +let region = ''; +if (!region.length && process.env.region) { + region = process.env.region; +} +try { + region = fs.readFileSync('region.txt', 'utf8').trim(); +} catch (err) { +} +if (region.length > 10 || !region.match(/^[a-z0-9_-]+$/i)) { + region = ''; +} + // Load default collections if (serveDefaultIcons) { const icons = require('simple-svg-icons'); @@ -135,8 +148,8 @@ app.get(/\/([a-z0-9\-]+)\/([a-z0-9\-,]+\.(js|json|svg))?$/, (req, res) => { // Debug information and AWS health check app.get('/version', (req, res) => { let body = 'SimpleSVG CDN version ' + version + ' (Node'; - if (process.env.region) { - body += ', ' + process.env.region; + if (region.length) { + body += ', ' + region; } body += ')'; res.send(body); diff --git a/package.json b/package.json index 40abd21..fad85bc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "simple-svg-website-icons", - "version": "0.0.6", + "version": "0.0.7", "description": "Node.js version of icons.simplesvg.com", "main": "app.js", "scripts": { @@ -9,8 +9,8 @@ "author": "Vjacheslav Trushkin", "license": "MIT", "dependencies": { - "express": "^4.15.2", - "simple-svg-cdn": "*", + "express": "^4.16.2", + "simple-svg-cdn": "^0.2.2", "simple-svg-icons": "git+https://github.com/simplesvg/icons.git" } }