please fix my code do not over complicate by importing other modules i just need to get this fixed:import express from 'express';
import PocketBase from 'pocketbase';
import dotenv from 'dotenv';

// Load environment variables from .env file
dotenv.config();

const __dirname = import.meta.url; // Adjust this to your context

// Initialize PocketBase client with the URL from environment variables
const pb = new PocketBase(process.env.POCKETBASE_URL); // Use the PocketBase URL from .env

const app = express();
const port = 3000;

// Middleware to handle JSON data
app.use(express.json());
app.use(express.static('webpages')); // Serve static HTML files

// Admin authentication route
app.post('/api/auth', (req, res) => {
    const { username, password } = req.body;

    // Check if the provided credentials match those in the environment variables
    if (username === process.env.ADMIN_EMAIL && password === process.env.ADMIN_PASSWORD) {
        // If authentication is successful, respond with a success message
        return res.status(200).json({ message: 'Authentication successful' });
    }

    // If authentication fails
    return res.status(403).json({ error: 'Unauthorized' });
});

// Fetch posts function (should be async)
async function fetchPosts() {
    try {
        const posts = await pb.collection('posts').getFullList({
            sort: '-created', // Sort by creation date (optional)
        });

        const filteredPosts = posts.map(post => ({
            id: post.id,
            title: post.title,
            md: post.md,
            created: new Date(post.created).toISOString().split('T')[0], // Convert to YYYY-MM-DD
        }));

        return JSON.stringify(filteredPosts, null, 2);
    } catch (error) {
        console.error('Error fetching posts:', error);
        return JSON.stringify({ error: 'Error fetching posts' });
    }
}

// Route for fetching posts
app.get('/api/thread', async (req, res) => {
    const posts = await fetchPosts();
    res.send(posts);
});

// Route for adding a new post (protected by authentication)
app.post('/api/add_post', async (req, res) => {
    const data = req.body;

    try {
        // Authenticate with PocketBase using the admin credentials from environment variables
        await pb.admins.authWithPassword(process.env.ADMIN_EMAIL, process.env.ADMIN_PASSWORD);

        const datam = {
            title: data.title,
            md: data.md,
        };

        // Create the new post in the 'posts' collection
        const record = await pb.collection('posts').create(datam);

        // Send a success response back to the client
        res.status(200).send({ message: 'Post successfully added!', data: record });
    } catch (error) {
        console.error('Error creating post:', error);
        res.status(500).send({ error: 'Error creating post' });
    }
});

// Routes for your admin and other pages
app.get('/', (req, res) => {
    res.sendFile(__dirname + '/webpages/index.html');
});

app.get('/blog', (req, res) => {
    res.sendFile(__dirname + '/webpages/blog.html');
});

app.get('/post/:id', (req, res) => {
    res.sendFile(__dirname + '/webpages/post.html');
});

app.get('/admin', (req, res) => {
    res.sendFile(__dirname + '/webpages/admin.html');
});

app.listen(port, () => {
    console.log(`Server is running on http://localhost:${port}`);
});
html:<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Admin Login</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background-color: #f4f4f4;
        }

        #login-container {
            background: white;
            padding: 20px;
            border-radius: 5px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }

        #login-error {
            color: red;
            display: none;
        }
    </style>
</head>

<body>
    <div id="login-container">
        <h2>Admin Login</h2>
        <form id="login-form">
            <div>
                <label for="username">Email:</label>
                <input type="email" id="username" required>
            </div>
            <div>
                <label for="password">Password:</label>
                <input type="password" id="password" required>
            </div>
            <div id="login-error"></div>
            <button type="submit">Login</button>
        </form>
    </div>

    <div id="admin-content" style="display: none;">
        <h2>Admin Panel</h2>
        <form id="blog-form">
            <input type="text" id="title" placeholder="Post Title" required>
            <textarea id="md" placeholder="Post Content" required></textarea>
            <button type="submit">Add Post</button>
        </form>
        <div id="posts-section"></div>
    </div>

    <script>
        const loginForm = document.getElementById('login-form');
        const adminContent = document.getElementById('admin-content');
        const loginContainer = document.getElementById('login-container');
        const loginError = document.getElementById('login-error');
        const form = document.getElementById('blog-form');
        const postsSection = document.getElementById('posts-section');

        // Function to handle login
        loginForm.addEventListener('submit', async (event) => {
            event.preventDefault(); // Prevent default form submission

            const username = document.getElementById('username').value;
            const password = document.getElementById('password').value;

            // Authenticate the user
            const authResponse = await fetch('/api/auth', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify({ username, password }), // Send credentials
            });

            if (authResponse.ok) {
                loginContainer.style.display = 'none'; // Hide login form
                adminContent.style.display = 'block'; // Show admin content
                fetchPosts(); // Fetch existing posts
            } else {
                const errorData = await authResponse.json();
                loginError.textContent = errorData.error; // Display error message
                loginError.style.display = 'block';
            }
        });

        // Function to fetch posts
        async function fetchPosts() {
            const response = await fetch('/api/thread');
            const posts = await response.json();
            displayPosts(posts);
        }

        // Function to display posts
        function displayPosts(posts) {
            postsSection.innerHTML = ''; // Clear previous posts
            posts.forEach(post => {
                const postElement = document.createElement('div');
                postElement.innerHTML = `<h3>${post.title}</h3><p>${post.md}</p><small>${post.created}</small>`;
                postsSection.appendChild(postElement);
            });
        }

        // Handle adding a new post
        form.addEventListener('submit', async (event) => {
            event.preventDefault(); // Prevent default form submission

            const title = document.getElementById('title').value;
            const md = document.getElementById('md').value;

            const postResponse = await fetch('/api/add_post', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify({ title, md }), // Send post data
            });

            if (postResponse.ok) {
                fetchPosts(); // Refresh the posts list
                form.reset(); // Reset the form
            } else {
                const errorData = await postResponse.json();
                console.error('Error adding post:', errorData.error);
            }
        });
    </script>
</body>

</html>