Public Access
1
0

feat: add proxy middleware for API requests and create production Docker Compose setup

This commit is contained in:
2025-08-23 11:27:40 -04:00
parent abfac06908
commit 0327ef81a6
5 changed files with 142 additions and 5 deletions

View File

@@ -3,12 +3,11 @@ document.addEventListener('DOMContentLoaded', () => {
if (viewCountElement) {
const slug = viewCountElement.dataset.slug;
const serverUrl = 'http://localhost:3000'; // IMPORTANT: Replace with your server's IP/domain
// Function to fetch and display the view count
const getViews = async () => {
try {
const response = await fetch(`${serverUrl}/api/views/${slug}`);
const response = await fetch(`/api/views/${slug}`);
if (!response.ok) throw new Error('Failed to fetch views');
const data = await response.json();
viewCountElement.textContent = `${data.count} views`;
@@ -24,7 +23,7 @@ document.addEventListener('DOMContentLoaded', () => {
// Use a flag in localStorage to prevent incrementing on every refresh
const viewed = localStorage.getItem(`viewed-${slug}`);
if (!viewed) {
await fetch(`${serverUrl}/api/views/${slug}`, { method: 'POST' });
await fetch(`/api/views/${slug}`, { method: 'POST' });
localStorage.setItem(`viewed-${slug}`, 'true');
}
} catch (error) {