-
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.
- Loading branch information
Showing
2 changed files
with
33 additions
and
10 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 |
---|---|---|
@@ -1,29 +1,43 @@ | ||
// Imports | ||
import { fileURLToPath } from 'url'; | ||
import { fileURLToPath } from 'url' | ||
import { Success, Error } from '../util/ResponseHandler.js' | ||
import path, { dirname } from 'path'; | ||
import express from 'express'; | ||
import fs from 'fs'; | ||
import path, { dirname } from 'path' | ||
import express from 'express' | ||
import fs from 'fs' | ||
|
||
const router = express.Router(); | ||
const router = express.Router() | ||
|
||
// File Handling | ||
const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
const FilePath = path.resolve(__dirname, '../data/band.json'); | ||
const __dirname = dirname(fileURLToPath(import.meta.url)) | ||
const FilePath = path.resolve(__dirname, '../data/band.json') | ||
|
||
// Middleware to read JSON file | ||
function readFile() { | ||
return JSON.parse(fs.readFileSync(FilePath, 'utf8')); | ||
return JSON.parse(fs.readFileSync(FilePath, 'utf8')) | ||
} | ||
|
||
// GET /albums - Get all albums | ||
router.get('/', (req, res) => { | ||
try { | ||
const band = readFile(); | ||
const band = readFile() | ||
Success(res, 200, band) | ||
} catch (err) { | ||
Error(res, 404, "fu") | ||
} | ||
}); | ||
|
||
// GET /albums - Get all albums | ||
router.get('/:type', (req, res) => { | ||
|
||
const type = req.params.type | ||
|
||
try { | ||
const band = readFile() | ||
const data = band[`${type}`] | ||
Success(res, 200, data) | ||
} catch (err) { | ||
Error(res, 404, "fu") | ||
} | ||
}); | ||
|
||
export default router; |