-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from oxsecurity/OXDEV-15954-fix-server-redirects
Move api routes under /api and serve index.html for all GET requests
- Loading branch information
Showing
7 changed files
with
42 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import config from "../../config"; | ||
|
||
const port = config.CODETOTAL_HTTP_PORT; | ||
const host = config.CODETOTAL_HTTP_HOST; | ||
const prefix = "api"; | ||
|
||
export const backendUrl = | ||
port === "80" || port === undefined | ||
? `//${host}/${prefix}` | ||
: `//${host}:${port}/${prefix}`; | ||
|
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 |
---|---|---|
@@ -1,11 +1,26 @@ | ||
import express from "express"; | ||
import fs from "node:fs"; | ||
import path from "node:path"; | ||
import { analysisHttpHandler } from "./handlers/analysis-http-handler"; | ||
import { multerFileUploadHandler } from "./handlers/http-file-upload-handler"; | ||
import { languageDetectionHttpHandler } from "./handlers/language-detection-http-handler"; | ||
import { reportHttpHandler } from "./handlers/report-http-handler"; | ||
|
||
export const registerRoutes = (app: express.Express) => { | ||
app.post("/analysis", multerFileUploadHandler, analysisHttpHandler); | ||
app.get("/report/:requestId", reportHttpHandler); | ||
app.post("/detect", languageDetectionHttpHandler); | ||
const prefix = "/api"; | ||
|
||
app.post(`${prefix}/analysis`, multerFileUploadHandler, analysisHttpHandler); | ||
app.get(`${prefix}/report/:requestId`, reportHttpHandler); | ||
app.post(`${prefix}/detect`, languageDetectionHttpHandler); | ||
|
||
if (process.env.NODE_ENV === "production") { | ||
const indexHTMLPath = path.resolve("./dist", "public", "index.html"); | ||
const indexHTML = fs.readFileSync(indexHTMLPath).toString(); | ||
console.log("Serving the following index.html file for all GET requests"); | ||
console.log(indexHTML); | ||
|
||
app.get("*", (req, res) => { | ||
res.send(indexHTML); | ||
}); | ||
} | ||
}; |