Created
December 22, 2023 21:30
-
-
Save onosendi/279e593aa5c95a2511677a4e963f0058 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function browser_routes({ | |
app, | |
auth_config, | |
app_type, | |
store, | |
options, | |
middleware, | |
}) { | |
app.post(options.auth_url, middleware, (req, res) => { | |
res.send('foo'); | |
}) | |
} | |
module.exports = browser_routes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const configure_browser_routes = require('./browser-routes'); | |
const configure_server_routes = require('./server-routes'); | |
const some_middleware = require('./some-middleware'); | |
function my_plugin(app, options) { | |
const { token_store: store } = options; | |
const auth_config = {}; | |
const app_type = app?.use ? 'express' : 'fastify'; | |
const middleware = some_middleware(options); | |
configure_browser_routes({ | |
app, | |
auth_config, | |
app_type, | |
store, | |
options, | |
middleware, | |
}); | |
configure_server_routes({ | |
app, | |
auth_config, | |
app_type, | |
store, | |
options, | |
middleware, | |
}); | |
} | |
module.exports = my_plugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function server_routes({ | |
app, | |
auth_config, | |
app_type, | |
store, | |
options, | |
middleware, | |
}) { | |
app.post(options.some_url, middleware, (req, res) => { | |
res.send('foo'); | |
}) | |
} | |
module.exports = server_routes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function some_middleware(options) { | |
return (req, res, next) => { | |
if (options.ips.includes(req.ip)) { | |
throw new Error('Foo'); | |
} | |
next(); | |
} | |
} | |
module.exports = some_middleware; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment