-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
4,535 additions
and
13 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
node_modules | ||
.github | ||
coommitlint.config.js | ||
example-app | ||
example |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import AdminJS from 'adminjs' | ||
import AdminJSKoa from '@adminjs/koa' | ||
import Koa from 'koa' | ||
|
||
const PORT = 3000 | ||
|
||
const DEFAULT_ADMIN = { | ||
email: 'admin@example.com', | ||
password: 'password', | ||
} | ||
|
||
const authenticate = async (email, password) => { | ||
if (email === DEFAULT_ADMIN.email && password === DEFAULT_ADMIN.password) { | ||
return Promise.resolve(DEFAULT_ADMIN) | ||
} | ||
return null | ||
} | ||
|
||
const start = async () => { | ||
const app = new Koa() | ||
|
||
const admin = new AdminJS({ | ||
resources: [], | ||
rootPath: '/admin', | ||
}) | ||
|
||
app.keys = ['your secret for koa cookie'] | ||
const router = AdminJSKoa.buildAuthenticatedRouter(admin, app, { | ||
authenticate, | ||
sessionOptions: { | ||
// You may configure your Koa session here | ||
httpOnly: process.env.NODE_ENV === 'production', | ||
secure: process.env.NODE_ENV === 'production', | ||
renew: true, | ||
}, | ||
}) | ||
|
||
app.use(router.routes()).use(router.allowedMethods()) | ||
|
||
app.listen(PORT, () => { | ||
console.log( | ||
`AdminJS available at http://localhost:${PORT}${admin.options.rootPath}`, | ||
) | ||
}) | ||
} | ||
|
||
start() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "example", | ||
"version": "1.0.0", | ||
"type": "module", | ||
"license": "MIT", | ||
"scripts": { | ||
"start:auth": "node auth.js", | ||
"dev:auth": "nodemon auth.js", | ||
"start:simple": "node simple.js", | ||
"dev:simple": "nodemon simple.js" | ||
}, | ||
"dependencies": { | ||
"@adminjs/koa": "file:../", | ||
"@koa/router": "^12.0.0", | ||
"adminjs": "^7.0.0", | ||
"koa": "^2.14.2", | ||
"koa2-formidable": "^1.0.3" | ||
}, | ||
"devDependencies": { | ||
"nodemon": "^2.0.22" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import AdminJS from 'adminjs' | ||
import AdminJSKoa from '@adminjs/koa' | ||
import Koa from 'koa' | ||
|
||
const PORT = 3000 | ||
|
||
const start = async () => { | ||
const app = new Koa() | ||
const admin = new AdminJS({ | ||
resources: [], | ||
rootPath: '/', | ||
}) | ||
|
||
const router = AdminJSKoa.buildRouter(admin, app) | ||
|
||
app | ||
.use(router.routes()) | ||
.use(router.allowedMethods()) | ||
|
||
app.listen(PORT, () => { | ||
console.log(`AdminJS available at http://localhost:${PORT}${admin.options.rootPath}`) | ||
}) | ||
} | ||
|
||
start() |
Oops, something went wrong.