add simple setup route
This commit is contained in:
@@ -22,6 +22,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/express": "^4.17.18",
|
"@types/express": "^4.17.18",
|
||||||
"@types/morgan": "^1.9.6",
|
"@types/morgan": "^1.9.6",
|
||||||
|
"@types/uuid": "^9.0.5",
|
||||||
"bun-types": "latest",
|
"bun-types": "latest",
|
||||||
"typescript": "^5.0.0"
|
"typescript": "^5.0.0"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
import express from "express";
|
import express from 'express'
|
||||||
import events from './routes/events'
|
import events from './routes/events'
|
||||||
import profiles from './routes/profiles'
|
import profiles from './routes/profiles'
|
||||||
import { authMiddleware } from "./middlewares/auth";
|
import { authMiddleware } from './middlewares/auth'
|
||||||
import morgan from 'morgan'
|
import morgan from 'morgan'
|
||||||
|
import { setup } from './routes/setup'
|
||||||
|
|
||||||
const app = express();
|
const app = express()
|
||||||
const port = process.env.PORT || 8080;
|
const port = process.env.PORT || 8080
|
||||||
|
|
||||||
app.use(express.json());
|
app.use(express.json())
|
||||||
app.use(morgan(':method :url :status :response-time ms'))
|
app.use(morgan(':method :url :status :response-time ms'))
|
||||||
app.get("/", (req, res) => res.json("Welcome to Mixan"));
|
app.get('/', (req, res) => res.json('Welcome to Mixan'))
|
||||||
app.use(authMiddleware)
|
app.use(authMiddleware)
|
||||||
app.use('/api/sdk',events)
|
app.use('/api/sdk', events)
|
||||||
app.use('/api/sdk',profiles)
|
app.use('/api/sdk', profiles)
|
||||||
|
if (process.env.SETUP) {
|
||||||
|
app.use('/setup', setup)
|
||||||
|
}
|
||||||
app.listen(port, () => {
|
app.listen(port, () => {
|
||||||
console.log(`Listening on port ${port}...`);
|
console.log(`Listening on port ${port}...`)
|
||||||
});
|
})
|
||||||
|
|||||||
37
apps/backend/src/routes/setup.ts
Normal file
37
apps/backend/src/routes/setup.ts
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import { Request, Response } from 'express'
|
||||||
|
import { db } from '../db'
|
||||||
|
import { makeError } from '../responses/errors'
|
||||||
|
import { v4 as uuid } from 'uuid'
|
||||||
|
|
||||||
|
export async function setup(req: Request, res: Response) {
|
||||||
|
try {
|
||||||
|
const organization = await db.organization.create({
|
||||||
|
data: {
|
||||||
|
name: 'Acme Inc.',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const project = await db.project.create({
|
||||||
|
data: {
|
||||||
|
name: 'Acme Website',
|
||||||
|
organization_id: organization.id,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const client = await db.client.create({
|
||||||
|
data: {
|
||||||
|
name: 'Acme Website Client',
|
||||||
|
project_id: project.id,
|
||||||
|
secret: uuid(),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
res.json({
|
||||||
|
organization,
|
||||||
|
project,
|
||||||
|
client,
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
res.json(makeError(error))
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user