Issuing Credentials
import express from "express";
import path from "path";
import {fileURLToPath} from "url";
import dotenv from "dotenv";
import issuerRouter from "./issuer-routes.js";
import jwt from "jsonwebtoken";
dotenv.config();
// Convert module URL to a __dirname-like value
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// PORT and BASE_URL come from .env (fallback to 3000 if not set)
const PORT = process.env.PORT || 3000;
const BASE_URL = process.env.BASE_URL || `http://localhost:${PORT}`;
// Initialize Express app
const app = express();
// Serve any static assets (e.g., index.html, scripts, styles) from public/
app.use(express.static(path.join(__dirname, "../public")));
// Parse URL-encoded bodies (HTML form submissions)
app.use(express.urlencoded({extended: true}));
// Attach our router (defined in src/issuer-routes.js)
app.use("/issuer", express.json(), issuerRouter);
// Start the server
app.listen(PORT, () => {
console.log(`Server is running on ${BASE_URL}`);
});Run the server:
Last updated