initial commit

This commit is contained in:
Bhavnoor Singh Saroya 2025-01-07 04:45:03 -08:00
commit b25eb51ff0
280 changed files with 178550 additions and 0 deletions

1
frontend-service/.env Normal file
View file

@ -0,0 +1 @@
PORT=3000

59
frontend-service/app.js Normal file
View file

@ -0,0 +1,59 @@
const express = require('express');
const path = require('path');
// use dotenv
require('dotenv').config();
const app = express();
const PORT = process.env.PORT || 3000;
// Serve static files like CSS and JS
// be careful with the path since we don't have auth
app.use('/static', express.static(path.join(__dirname, 'static')));
app.use('/html', express.static(path.join(__dirname, 'html')));
// Root route
app.get('/', (req, res) => {
// Send the index.html file, which features lazy loading
res.sendFile(path.join(__dirname, 'html', 'index.html'));
});
//verify jwt token or gateway signature
// Lazy-loaded content endpoint
app.get('/content', (req, res) => {
// Send the lazy-loaded content but server render it as html, perhaps use a template engine if needed
res.send('<h1>Welcome to the lazy-loaded content!</h1><p>This content was loaded dynamically.</p>');
});
// Login route, is this redundant? might be cuz we have a login.html file
app.get('/login', (req, res) => {
res.sendFile(path.join(__dirname, 'html', 'login.html'));
});
// Start the server
app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});
// Directory structure suggestion:
// - static/
// - styles.css
// - html/
// - index.html
// - login.html
// - app.js
// static/styles.css content:
// #loader {
// font-size: 1.5em;
// text-align: center;
// margin-top: 20%;
// color: #555;
// }
// #content {
// font-family: Arial, sans-serif;
// margin: 20px;
// text-align: center;
// }

View file

View file

@ -0,0 +1,30 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
<link rel="stylesheet" href="/static/styles.css">
</head>
<body>
<div id="loader">Loading...</div>
<div id="content" style="display: none;"></div>
<script>
// Simulate a delay to show the loader
setTimeout(() => {
fetch('/content')
.then(response => response.text())
.then(data => {
document.getElementById('loader').style.display = 'none';
const contentDiv = document.getElementById('content');
contentDiv.style.display = 'block';
contentDiv.innerHTML = data;
})
.catch(err => {
document.getElementById('loader').innerText = 'Failed to load content.';
});
}, 1000); // 1 second delay to simulate loading
</script>
</body>
</html>

View file

@ -0,0 +1,3 @@
# frontend microservice
- serve static html files
- serve other static assets