Skip to content

Commit

Permalink
Application.get post 메소드 구현 및 Middleware 실행 코드 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
김정환 committed Nov 14, 2018
1 parent 6ffb75b commit 4c1e030
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ const Application = () => {
_middleware.add(fn);
}

const get = (path, fn) => {
if (!path || !fn) throw Error('path and fn is required');
fn._method = 'get';
use(path, fn)
}

const post = (path, fn) => {
if (!path || !fn) throw Error('path and fn is required');
fn._method = 'post';
use(path, fn)
}

const listen = (port = 3000, hostname = '127.0.0.1', fn) => {
_server.listen(port, hostname, fn);

Expand All @@ -33,6 +45,8 @@ const Application = () => {
_middleware,
_server,
use,
get,
post,
listen
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const Middleware = () => {
}

if (nextMw._path) {
const pathMatched = _req.path === nextMw._path;
const pathMatched = _req.path === nextMw._path &&
_req.method.toLowerCase() === (nextMw._method || 'get');
return pathMatched ? nextMw(_req, _res, next) : _run(i + 1)
}

Expand Down

0 comments on commit 4c1e030

Please sign in to comment.