-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding express routing to backend (#52)
- Loading branch information
Showing
4 changed files
with
41 additions
and
0 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
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 { Request, Response } from 'express'; | ||
import { GptService } from '../services/gptService'; | ||
|
||
export const GptController = { | ||
async ask(req: Request, res: Response) { | ||
try { | ||
if (!req.body) { | ||
return res.status(400).json({ success: false, message: 'Empty body' }); | ||
} | ||
|
||
let gptService = new GptService(); | ||
let data = gptService.doSomething(); | ||
|
||
res.status(200).json({ success: true, message: 'Reached the backend successfully', data }); | ||
} catch (err) { | ||
if (err instanceof Error) { | ||
res.status(500).json({ success: false, message: 'Failed to ask gpt', error: err.message }); | ||
} else { | ||
res | ||
.status(500) | ||
.json({ success: false, message: 'Failed to ask gpt', error: 'Unknown error' }); | ||
} | ||
} | ||
}, | ||
}; |
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,8 @@ | ||
import express from 'express'; | ||
import { GptController } from '../controllers/gptController'; | ||
|
||
const router = express.Router(); | ||
|
||
router.post('/ask', GptController.ask); | ||
|
||
export default router; |
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,6 @@ | ||
export class GptService { | ||
doSomething = () => { | ||
console.log('inside the gpt service'); | ||
return "called gpt" | ||
}; | ||
} |