Skip to content

Commit

Permalink
chore: add updated dist
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Jul 26, 2017
1 parent 997712e commit 58bfdba
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

const UrlPattern = require('url-pattern');
const { send } = require('micro');
const { getParamsAndQuery } = require('../utils');

const METHODS = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'];
Expand All @@ -8,8 +10,10 @@ const methodFn = method => (path, handler) => {
if (!path) throw new Error('You need to set a valid path');
if (!handler) throw new Error('You need to set a valid handler');

const route = new UrlPattern(path);

return (req, res) => {
const { params, query } = getParamsAndQuery(path, req.url);
const { params, query } = getParamsAndQuery(route, req.url);

if (params && req.method === method) {
return handler(Object.assign(req, { params, query }), res);
Expand All @@ -23,6 +27,8 @@ exports.router = (...funcs) => (() => {
const result = yield fn(req, res);
if (result || res.headersSent) return result;
}

send(res, 404, `Cannot ${req.method} ${req.url}`);
});

return function (_x, _x2) {
Expand Down

0 comments on commit 58bfdba

Please sign in to comment.