This commit is contained in:
Tom Moor
2017-05-27 11:22:42 -07:00
parent 639a0ec45c
commit 044486b9a6
4 changed files with 8 additions and 21 deletions

View File

@ -48,7 +48,7 @@ export default function auth({ require = true } = {}) {
},
});
} catch (e) {
throw httpErrors.Unauthorized('Invalid api key');
throw httpErrors.Unauthorized('Invalid API key');
}
if (!apiKey) throw httpErrors.Unauthorized('Invalid token');

View File

@ -1,19 +1,17 @@
import httpErrors from 'http-errors';
var querystring = require('querystring');
import querystring from 'querystring';
export default function pagination(options) {
return async function paginationMiddleware(ctx, next) {
const opts = {
...{
defaultLimit: 15,
maxLimit: 100,
},
...options,
};
let query = ctx.request.query;
let limit = parseInt(query.limit);
let offset = parseInt(query.offset);
let limit = parseInt(query.limit, 10);
let offset = parseInt(query.offset, 10);
limit = isNaN(limit) ? opts.defaultLimit : limit;
offset = isNaN(offset) ? 0 : offset;
@ -30,8 +28,7 @@ export default function pagination(options) {
query.limit = ctx.state.pagination.limit;
query.offset = ctx.state.pagination.offset + query.limit;
ctx.state.pagination.nextPath =
'/api' + ctx.request.path + '?' + querystring.stringify(query);
ctx.state.pagination.nextPath = `/api${ctx.request.path}?${querystring.stringify(query)}`;
return next();
};

View File

@ -1,7 +1,7 @@
export default function subdomainRedirect(options) {
return async function subdomainRedirectMiddleware(ctx, next) {
if (ctx.headers.host === 'beautifulatlas.com') {
ctx.redirect('https://www.' + ctx.headers.host + ctx.path);
ctx.redirect(`https://www.${ctx.headers.host}${ctx.path}`);
} else {
return next();
}

View File

@ -32,15 +32,5 @@
<div class="header"></div>
</div>
</div>
<script type="text/javascript">
// if ('serviceWorker' in navigator) {
// navigator.serviceWorker.register('/service-worker.js')
// .then(function(reg) {
// console.log('SW registration succeeded');
// }).catch(function(error) {
// console.log('SW registration failed: ' + error);
// });
// };
</script>
</body>
</html>