-
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.
Merge branch 'main' of https://github.com/junidy/COP4710Project
- Loading branch information
Showing
14 changed files
with
196 additions
and
469 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
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
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,33 @@ | ||
import express from 'express'; | ||
import { promisify } from 'util'; | ||
import mysql from 'mysql2'; | ||
|
||
import dotenv from 'dotenv'; | ||
dotenv.config(); | ||
|
||
const router = express.Router(); | ||
const db = mysql.createPool({ | ||
host: process.env.DB_HOST || 'localhost', | ||
port: process.env.DB_PORT || 3306, | ||
user: process.env.DB_USER || 'root', | ||
password: process.env.DB_PASS || 'password', | ||
database: process.env.DB_NAME || 'cop4710' | ||
}); | ||
const query = promisify(db.query).bind(db); | ||
|
||
// Return a list of university names | ||
router.get('/', async (req, res) => { | ||
try { | ||
const universities = await query('SELECT university_id, name FROM universities'); | ||
const formattedResponse = universities.map(university => ({ | ||
id: university.university_id, | ||
name: university.name | ||
})); | ||
res.json(formattedResponse); | ||
} catch (error) { | ||
console.error(error); | ||
res.status(500).json({ error: 'Internal server error' }); | ||
} | ||
}); | ||
|
||
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
Oops, something went wrong.