Skip to content

Instantly share code, notes, and snippets.

@beardedtim
Created April 24, 2017 04:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beardedtim/52d991ca30d61cc59d5878c05b263a85 to your computer and use it in GitHub Desktop.
Save beardedtim/52d991ca30d61cc59d5878c05b263a85 to your computer and use it in GitHub Desktop.
@beardedtim/cms v 0.0.1 example usage
const Koa = require('koa');
const dotenv = require('dotenv');
const cmsServer = require('@beardedtim/cms').server;
dotenv.config();
const defaultApp = new Koa();
cmsServer.booststrap(defaultApp);
defaultApp.listen(
process.env.PORT, () => console.log('listening at %s', process.env.PORT)
);
const configuration = {
collections: [
{
resource: 'users',
pre: [
async (ctx, next) => {
const doIt = Math.random();
if (doIt > 0.5) {
ctx.body = {
data: {
never: {
gonna: {
give: {
you: 'up'
}
}
}
}
}
} else {
return next();
}
}
],
protected: true,
authFn: async (ctx, next) => {
console.log('You are authorized!')
await next();
console.log('Hopefully it worked out!');
}
}
]
}
const configuredApp = new Koa();
cmsServer.booststrap(configuredApp, configuration);
configuredApp.listen(
Number(process.env.PORT) + 1, () => console.log('listening at %s', Number(process.env.PORT) + 1)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment