Skip to content

Commit

Permalink
chore: testing build
Browse files Browse the repository at this point in the history
  • Loading branch information
devops-chris committed Feb 26, 2024
1 parent 902c029 commit 881213a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dev_fe_build_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:
push:
branches:
- main
- cml/data-tools
paths:
- 'frontend/**'

Expand Down
42 changes: 24 additions & 18 deletions frontend/index.js
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);
}
});
}
});

0 comments on commit 881213a

Please sign in to comment.