Created
April 24, 2017 04:01
-
-
Save beardedtim/52d991ca30d61cc59d5878c05b263a85 to your computer and use it in GitHub Desktop.
@beardedtim/cms v 0.0.1 example usage
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 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