Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions backend/migrations/20250321142114_add_github_fields_to_users.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { Knex } from 'knex'

/**
* Migration to add GitHub integration fields to users table
*/
export async function up(knex: Knex): Promise<void> {
await knex.schema.alterTable('users', table => {
table.string('github_token').nullable()
table.string('github_username').nullable()
table.string('github_email').nullable()
table.string('github_name').nullable()
table.timestamp('github_connected_at').nullable()
})
}

/**
* Rollback function to remove GitHub-related fields
*/
export async function down(knex: Knex): Promise<void> {
await knex.schema.alterTable('users', table => {
table.dropColumn('github_token')
table.dropColumn('github_username')
table.dropColumn('github_email')
table.dropColumn('github_name')
table.dropColumn('github_connected_at')
})
}
24 changes: 20 additions & 4 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"express": "^4.18.3",
"express-rate-limit": "^7.5.0",
"knex": "^3.1.0",
"mysql2": "^3.9.2",
"openai": "^4.86.2",
Expand All @@ -30,7 +31,7 @@
"@types/cors": "^2.8.17",
"@types/express": "^4.17.21",
"@types/jest": "^29.5.12",
"@types/node": "^20.11.28",
"@types/node": "^20.17.27",
"@types/supertest": "^6.0.2",
"@typescript-eslint/eslint-plugin": "^8.24.1",
"@typescript-eslint/parser": "^8.24.1",
Expand Down
20 changes: 20 additions & 0 deletions backend/src/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import express from 'express'
import cors from 'cors'
import dotenv from 'dotenv'
import { createGitHubRouter } from './routes/github'
import { Knex } from 'knex'

dotenv.config()

// Define properly typed db import
const db = {} as Knex

const app = express()

app.use(cors())
app.use(express.json())

// Routes
app.use('/api/github', createGitHubRouter(db))

export default app
22 changes: 18 additions & 4 deletions backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import { createAppsRouter } from './routes/apps'
import { createUsersRouter } from './routes/users'
import { createTemplatesRouter } from './routes/templates'
import { createAiRouter } from './routes/ai'
import { createGitHubRouter } from './routes/github'
import cors from 'cors'
import { Request, Response, NextFunction } from 'express'

// Load environment variables
dotenv.config()
Expand Down Expand Up @@ -35,21 +37,33 @@ db.raw('SELECT 1')
app.use(cors())
app.use(express.json())

// Log all incoming requests
app.use((req, res, next) => {
console.log(`${req.method} ${req.url}`)
next()
})

// Add error handling middleware
app.use((_err: unknown, _req: express.Request, res: express.Response, _next: express.NextFunction) => {
console.error('Unhandled error:', _err)
res.status(500).json({ error: 'Internal server error' })
app.use((error: Error, req: Request, res: Response, _next: NextFunction) => {
console.error('Unhandled error:', error)
return res.status(500).json({ error: 'Internal server error' })
})

// Routes
app.use('/api', createAppsRouter(db))
app.use('/api', createUsersRouter(db))
app.use('/api/templates', createTemplatesRouter(db))
app.use('/api/ai', createAiRouter(db))
app.use('/api/github', createGitHubRouter(db))

// Test route
app.get('/api/health', (req, res) => {
res.json({ status: 'ok', timestamp: new Date().toISOString() })
})

const port = process.env.PORT || 3001
app.listen(port, () => {
console.log(`Server running on port ${port}`)
console.log(`Server started on port ${port}`)
console.log(`Environment: ${process.env.NODE_ENV || 'development'}`)
})

Expand Down
Loading
Loading