-
Notifications
You must be signed in to change notification settings - Fork 3
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
1 parent
902c029
commit 881213a
Showing
2 changed files
with
25 additions
and
19 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 |
---|---|---|
|
@@ -4,7 +4,7 @@ on: | |
workflow_dispatch: | ||
push: | ||
branches: | ||
- main | ||
- cml/data-tools | ||
paths: | ||
- 'frontend/**' | ||
|
||
|
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,30 @@ | ||
// Temporary server for Azure Dev | ||
const BASE_PATH = "./"; | ||
|
||
Bun.serve({ | ||
port: 3000, | ||
async fetch(req) { | ||
const url = new URL(req.url); | ||
let filePath = BASE_PATH + url.pathname; | ||
port: 3000, | ||
async fetch(req) { | ||
const url = new URL(req.url); | ||
let filePath; | ||
|
||
// If the request is for "/", serve the "index.html" file | ||
if (url.pathname === "/") { | ||
filePath = BASE_PATH + "/index.html"; | ||
} | ||
// If the request is for "/", serve the "index.html" file | ||
if (url.pathname === "/") { | ||
filePath = BASE_PATH + "/index.html"; | ||
} else if (url.pathname.startsWith("/static")) { | ||
// If the request starts with "/static", serve files from the "/static" directory | ||
filePath = BASE_PATH + url.pathname.replace(/^\/static/, "/static"); | ||
} else { | ||
// For all other routes, serve files directly from the root directory | ||
filePath = BASE_PATH + url.pathname; | ||
} | ||
|
||
const file = Bun.file(filePath); | ||
return new Response(file); | ||
}, | ||
error() { | ||
// If error, route to index.html | ||
let filePath = BASE_PATH + "/index.html"; | ||
const file = Bun.file(filePath); | ||
return new Response(file); | ||
try { | ||
const file = await Bun.file(filePath); | ||
return new Response(file); | ||
} catch (error) { | ||
// If error, route to index.html | ||
let indexPath = BASE_PATH + "/index.html"; | ||
const indexFile = await Bun.file(indexPath); | ||
return new Response(indexFile); | ||
} | ||
}); | ||
} | ||
}); |