Open i2xzy opened 6 years ago
your handlers are your own function so they can expect any arguments you want. If the only thing you're doing with an argument is extracting something from it, then you can do that extracting before you call the function.
const { homeHandler, staticHandler } = require('./handlers.js') const { url } = request.url; if (url === '/') { homeHandler(response); } else if (url.indexOf('/public') === 0) { staticHandler(url, response); }
const homeHandler = (response) => { ... response.end(file); }; const staticHandler = (url, response) => { ... // use url to get correct file ... response.end(file); }
your handlers are your own function so they can expect any arguments you want. If the only thing you're doing with an argument is extracting something from it, then you can do that extracting before you call the function.