Skip to content

Commit

Permalink
Working admin, broken views
Browse files Browse the repository at this point in the history
  • Loading branch information
alukach committed Feb 7, 2024
1 parent 37f0373 commit 332a54a
Show file tree
Hide file tree
Showing 5 changed files with 4,183 additions and 351 deletions.
6 changes: 6 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ const nextConfig = {
images: {
domains: ["pbs.twimg.com", "fakeimg.pl"],
},
rewrites: () => [
{
source: "/:admin*",
destination: "/api/admin/:admin*",
},
],
}

module.exports = nextConfig
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,22 @@
"seed": "ts-node --compiler-options {\"module\":\"CommonJS\"} prisma/seed.ts"
},
"dependencies": {
"@adminjs/express": "^6.1.0",
"@adminjs/prisma": "^5.0.2",
"@mapbox/mapbox-gl-draw": "^1.4.3",
"@prisma/client": "4.13.0",
"@prisma/client": "5.9.1",
"@turf/boolean-intersects": "^6.5.0",
"@turf/turf": "^6.5.0",
"@types/node": "^20",
"@types/react": "^18.2.48",
"@types/react-dom": "^18.2.18",
"adminjs": "^7.5.10",
"autoprefixer": "10.4.14",
"eslint": "8.38.0",
"eslint-config-next": "13.3.0",
"express": "^4.18.2",
"express-formidable": "^1.2.0",
"express-session": "^1.18.0",
"lodash-es": "^4.17.21",
"maplibre-gl": "^3.1.0",
"ms": "^2.1.3",
Expand Down
68 changes: 68 additions & 0 deletions pages/api/admin/[...admin].ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import AdminJS from "adminjs"
import { AdminJSOptions } from "adminjs"
import AdminJSExpress from "@adminjs/express"
import { Database, Resource, getModelByName } from "@adminjs/prisma"
import express, { Request, Response } from "express"

import prisma from "@/lib/prisma"

AdminJS.registerAdapter({ Database, Resource })

console.log("running expressjs")

const options: AdminJSOptions = {
rootPath: "/admin",
branding: {
companyName: "My Company",
withMadeWithLove: false,
},
locale: {
language: "en", // default language
availableLanguages: ["en"],
localeDetection: true,
},
resources: [
{
resource: { model: getModelByName("Study"), client: prisma },
options: {},
},
],
}

const adminJs = new AdminJS(options)
const app = express()
app.use(adminJs.options.rootPath, AdminJSExpress.buildRouter(adminJs))

// adminJs.watch()

const handler = (req: Request, res: Response) => {
app(req, res, err => {
console.log("express handling")

if (!res.headersSent) {
console.warn("no headers sent")
}

if (err) {
console.error(err)
res.status(err.status || 500).end(err.message)
} else {
res.end()
}
})
}

export default handler

export const config = {
api: {
// Defaults to true. Setting this to false disables body parsing and allows you to consume the request body as stream or raw-body.
bodyParser: false,

// Determines how much data should be sent from the response body. It is automatically enabled and defaults to 4mb.
responseLimit: false,

// Disables warnings for unresolved requests if the route is being handled by an external resolver like Express.js or Connect. Defaults to false.
externalResolver: true,
},
}

0 comments on commit 332a54a

Please sign in to comment.