Skip to content

Instantly share code, notes, and snippets.

@anshulrgoyal
Last active December 19, 2018 17:17
Show Gist options
  • Select an option

  • Save anshulrgoyal/dcaefdccaae6a1e3ba81c3cfde7a768e to your computer and use it in GitHub Desktop.

Select an option

Save anshulrgoyal/dcaefdccaae6a1e3ba81c3cfde7a768e to your computer and use it in GitHub Desktop.
Handler Example
const handler = {
// if path is localhost:3000/user
user: (data, cb) => {
const {
method
} = data;
const allowedMethods = ["post", "get"];
if (allowedMethods.indexOf(method) !== -1) {
handler._count[method](data, cb);
} else {
cb(
405, {
err: "unknown method"
},
"json"
);
}
},
_count: {
// if method is post
post: (data, cb) => {
// do something
},
get: (data, cb) => {
// do something more
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment