Browse Source

Use xo-lukechilds

pull/15/merge
Luke Childs 7 years ago
parent
commit
0b31522e46
  1. 2
      controllers/error.js
  2. 2
      controllers/error404.js
  3. 6
      index.js
  4. 4
      lib/tor.js
  5. 10
      now.json
  6. 6
      package.json
  7. 2
      public/sw.js

2
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 });
};

2
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 });
};

6
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);

4
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 {

10
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"
}
}

6
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"

2
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) {

Loading…
Cancel
Save