From 0b31522e4652adbb7ea5bbc982838e2a51741131 Mon Sep 17 00:00:00 2001 From: Luke Childs Date: Thu, 30 Nov 2017 12:57:41 +0700 Subject: [PATCH] Use xo-lukechilds --- controllers/error.js | 2 +- controllers/error404.js | 2 +- index.js | 6 +++--- lib/tor.js | 4 ++-- now.json | 10 ++++++++++ package.json | 6 ++++++ public/sw.js | 2 +- 7 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 now.json diff --git a/controllers/error.js b/controllers/error.js index b34f0c2..6d83206 100644 --- a/controllers/error.js +++ b/controllers/error.js @@ -3,5 +3,5 @@ module.exports = (err, req, res, next) => { const statusCode = err.statusCode || 500; const error = err.statusMessage || 'Something went wrong'; console.error(err); - res.status(statusCode).render('error.html', {error}); + res.status(statusCode).render('error.html', { error }); }; diff --git a/controllers/error404.js b/controllers/error404.js index 7ae7601..df0006f 100644 --- a/controllers/error404.js +++ b/controllers/error404.js @@ -1,5 +1,5 @@ module.exports = (req, res) => { const statusCode = 404; const error = '404 Not Found'; - res.status(statusCode).render('error.html', {error}); + res.status(statusCode).render('error.html', { error }); }; diff --git a/index.js b/index.js index 7a07b6e..85d844a 100644 --- a/index.js +++ b/index.js @@ -19,7 +19,7 @@ if (process.env.NOW) { app.use(anonlytics()); // Setup nunjucks -nunjucks.configure('views', {express: app}); +nunjucks.configure('views', { express: app }); nunjucksFilters(app); app.use(nunjucksMiddleware); @@ -36,8 +36,8 @@ app.get('/about', controllers.about); app.get('/no-connection', controllers.noConnection); // Serve assets with cache headers -app.use('/sw.js', express.static(`${__dirname}/public/sw.js`, {maxAge: '1 hour'})); -app.use(express.static(`${__dirname}/public`, {maxAge: '1 year'})); +app.use('/sw.js', express.static(`${__dirname}/public/sw.js`, { maxAge: '1 hour' })); +app.use(express.static(`${__dirname}/public`, { maxAge: '1 year' })); // Errors app.use(controllers.error404); diff --git a/lib/tor.js b/lib/tor.js index 4772d1c..55a8fe7 100644 --- a/lib/tor.js +++ b/lib/tor.js @@ -22,7 +22,7 @@ module.exports = { }, node: id => { return onionoo - .details({lookup: id}) + .details({ lookup: id }) .then(response => { const details = response.body; if (details.relays[0]) { @@ -36,7 +36,7 @@ module.exports = { }, bandwidth: id => { return onionoo - .bandwidth({lookup: id}) + .bandwidth({ lookup: id }) .then(response => { const bandwidth = response.body; try { diff --git a/now.json b/now.json new file mode 100644 index 0000000..896a484 --- /dev/null +++ b/now.json @@ -0,0 +1,10 @@ +{ + "name": "onionite", + "alias": "onionite", + "public": true, + "env": { + "NODE_ENV": "production", + "KEEN_PROJECT_ID": "@keen_project_id", + "KEEN_WRITE_KEY": "@keen_write_key" + } +} diff --git a/package.json b/package.json index c84bd18..825ddff 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "quick-lru": "^1.1.0" }, "devDependencies": { + "eslint-config-xo-lukechilds": "^1.0.1", "nodemon": "^1.10.2", "xo": "^0.17.1" }, @@ -28,8 +29,13 @@ "start": "node index.js", "dev": "nodemon -e js,json,html", "lint": "xo", + "deploy": "now --public", + "alias": "now alias", "test": "echo \"Error: no test specified\" && exit 1" }, + "xo": { + "extends": "xo-lukechilds" + }, "repository": { "type": "git", "url": "git+https://github.com/lukechilds/onionite.git" diff --git a/public/sw.js b/public/sw.js index d430dbd..dc902c9 100644 --- a/public/sw.js +++ b/public/sw.js @@ -58,7 +58,7 @@ self.addEventListener('fetch', function (event) { response.clone().text().then(function (html) { // Modify the html so we know when it was cached html = html.replace('window.cacheDate=false;', 'window.cacheDate="' + Date() + '";'); - var modifiedResponse = new Response(new Blob([html]), {headers: response.headers}); + var modifiedResponse = new Response(new Blob([html]), { headers: response.headers }); // Cache the modified response caches.open(cacheName).then(function (cache) {