Skip to content

Commit

Permalink
new approach
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadim Ritter committed Aug 28, 2024
1 parent 012501b commit 170f4d3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 18 deletions.
48 changes: 30 additions & 18 deletions server/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,56 @@ import {LOG} from "./logging/logger";
import {apiRequestLogger} from "./logging/api-request-logger";
import * as ENV from "./config/envConfig";


const app: Express = express();

const port: string = ENV.SERVER_PORT;
const path: string = __dirname + "/views/";

//get environemnt mode for local dev and set cors options
LOG.info("env mode: " + ENV.NODE_ENV);
if(ENV.NODE_ENV === "dev"){
app.use(cors(getCorstOptions()))
// app.use(cors())
const mainIndexPath: string = path + "index.html";

// Get environment mode for local dev and set CORS options
if (ENV.NODE_ENV === "dev") {
app.use(cors(getCorstOptions()));
}

app.use(express.static(path));
app.use(bodyParser.json());
// Middleware
app.use(apiRequestLogger);

app.use(authorizationRoutes);
app.use(routes);
// Static files config with dynamic base path
const basePath = ENV.BASE_PATH || "/";
app.use(basePath, express.static(path));
app.use(bodyParser.json());

// API routes
app.use(basePath, authorizationRoutes);
app.use(basePath, routes);

app.get("/", (req: Request, res: Response) => {
res.sendFile(path + "index.html");
// Static files route with dynamic base path
app.get(basePath + "/", (req: Request, res: Response) => {
console.log("Serving main index at:", mainIndexPath);
res.sendFile(mainIndexPath);
});

app.get("*", (req: Request, res: Response) => {
res.sendFile(path + "index.html");
// Catch-all route to handle all other requests
app.get(basePath + "/*", (req: Request, res: Response) => {
console.log("Catch-all route, serving main index at:", mainIndexPath);
res.sendFile(mainIndexPath);
});

app.listen(port, () => {
LOG.info(`⚡️[server]: Server is running at 0.0.0.0 ${port}`);
// Server startup
app.listen(port, async () => {
LOG.info(`⚡️[server]: Server is running at : ${port}`);
LOG.info("env mode: " + ENV.NODE_ENV);
LOG.info("is seb-server integrated: " + ENV.SEB_SERVER_INTEGRATED_MODE);
LOG.info("base path: " + ENV.BASE_PATH);
LOG.info(`screen-proctoring-server: ${ENV.PROCTOR_SERVER_URL}${ENV.PROCTOR_SERVER_PORT}`);
});

function getCorstOptions(): object{
function getCorstOptions(): object {
return {
origin: `${ENV.DEV_SERVER_URL}:${ENV.DEV_SERVER_PORT}`,
allowedHeaders: "Content-Type, authorization",
methods: "GET, POST",
credentials: true,
};
}
}
9 changes: 9 additions & 0 deletions server/src/config/envConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,18 @@ export const PROCTOR_SERVER_PASSWORD = process.env.PROCTOR_SERVER_PASSWORD;

export const SEB_SERVER_INTEGRATED_MODE = process.env.SEB_SERVER_INTEGRATED_MODE;

export const BASE_PATH = getBasePath();

function getServerPort(){
if(!process.env.PROCTOR_SERVER_PORT){
return "";
}
return ":" + process.env.PROCTOR_SERVER_PORT;
};

function getBasePath(){
if(!process.env.VITE_BASE_PATH){
return "";
}
return process.env.VITE_BASE_PATH;
};

0 comments on commit 170f4d3

Please sign in to comment.