-
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' into samuel/PWW-41
- Loading branch information
Showing
29 changed files
with
1,437 additions
and
190 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,3 +30,5 @@ | |
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
**/**/.env |
Large diffs are not rendered by default.
Oops, something went wrong.
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,35 @@ | ||
import { Request, Response, NextFunction } from "express"; | ||
import { | ||
InvalidTokenError, | ||
UnauthorizedError, | ||
} from "express-oauth2-jwt-bearer"; | ||
|
||
export const errorHandler = ( | ||
error: any, | ||
request: Request, | ||
response: Response, | ||
next: NextFunction, | ||
) => { | ||
console.log("Auth Error"); | ||
|
||
if (error instanceof InvalidTokenError) { | ||
const message = "Bad credentials"; | ||
|
||
response.status(error.status).json({ message }); | ||
|
||
return; | ||
} | ||
|
||
if (error instanceof UnauthorizedError) { | ||
const message = "Requires authentication"; | ||
|
||
response.status(error.status).json({ message }); | ||
|
||
return; | ||
} | ||
|
||
const status = 500; | ||
const message = "Internal Server Error"; | ||
|
||
response.status(status).json({ message }); | ||
}; |
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,21 @@ | ||
import { auth } from "express-oauth2-jwt-bearer"; | ||
import dotenv from "dotenv"; | ||
import path from "path"; | ||
|
||
dotenv.config({ path: path.resolve(__dirname, "../.env") }); | ||
|
||
const auth0Domain = process.env.AUTH0_DOMAIN; | ||
const auth0Audience = process.env.AUTH0_AUDIENCE; | ||
|
||
try { | ||
if (!auth0Domain || !auth0Audience) { | ||
throw new Error("AUTH0_DOMAIN or AUTH0_AUDIENCE is not set"); | ||
} | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
|
||
export const validateAccessToken = auth({ | ||
issuerBaseURL: `https://${auth0Domain}`, | ||
audience: auth0Audience, | ||
}); |
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,11 @@ | ||
import { Request, Response, NextFunction } from "express"; | ||
|
||
export const notFoundHandler = ( | ||
request: Request, | ||
response: Response, | ||
next: NextFunction, | ||
) => { | ||
const message = "Not Found"; | ||
|
||
response.status(404).json({ message }); | ||
}; |
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 |
---|---|---|
@@ -1,24 +1,23 @@ | ||
import dotenv from "dotenv"; | ||
import path from "path"; | ||
|
||
dotenv.config({ path: path.resolve(__dirname, "../.env") }); | ||
|
||
import express from "express"; | ||
import bodyParser from "body-parser"; | ||
import connectDB from "./config/db"; | ||
import * as routes from "./routes/index"; | ||
import path from "path"; | ||
|
||
var cors = require("cors"); | ||
|
||
const app = express(); | ||
app.use(cors()); | ||
app.use(cors({ origin: "http://localhost:3000" })); // Connect to the frontend PORT 3000 | ||
app.use(bodyParser.json()); | ||
app.use(bodyParser.urlencoded({ extended: true })); | ||
|
||
app.use("/user", routes.user); | ||
app.use("/workshop", routes.workshop); | ||
|
||
connectDB(); | ||
|
||
app.listen(process.env.PORT || 8000, () => | ||
console.log(`Server running on port ${process.env.PORT || 8000}`), | ||
); | ||
import * as routes from "./routes/index"; | ||
app.use("/user", routes.user); | ||
app.use("/api", routes.workshop); // New workshop route | ||
|
||
app.listen(process.env.PORT || 8000, () => console.log("Server running...")); |
Oops, something went wrong.