Skip to content

Instantly share code, notes, and snippets.

@onosendi
Created December 22, 2023 21:30
Show Gist options
  • Save onosendi/279e593aa5c95a2511677a4e963f0058 to your computer and use it in GitHub Desktop.
Save onosendi/279e593aa5c95a2511677a4e963f0058 to your computer and use it in GitHub Desktop.
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;
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;
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;
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