-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.js
69 lines (60 loc) · 2.18 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// main file
import express from "express";
import router from "./routes/preAuthSDjwRoutes.js";
import verifierRouter from "./routes/verifierRoutes.js";
import metadataRouter from "./routes/metadataroutes.js";
import codeFlowRouter from "./routes/codeFlowJwtRoutes.js";
import codeFlowRouterSDJWT from "./routes/codeFlowSdJwtRoutes.js";
import boardingPassRouter from "./routes/boardingPassRoutes.js";
import pidRouter from "./routes/pidroutes.js";
import passportRouter from "./routes/passportRoutes.js";
import didWebRouter from "./routes/didweb.js"
import educationalRouter from "./routes/educationalRoutes.js";
import bodyParser from "body-parser"; // Body parser middleware
import * as OpenApiValidator from "express-openapi-validator";
import path from "path";
// Path to your OpenAPI spec file (JSON or YAML)
const apiSpec = path.join(process.cwd(), "openapi.yaml");
const app = express();
const port = 3000;
// Middleware to parse URL-encoded bodies
app.use(express.urlencoded({ extended: true }));
// Middleware for post bodies
app.use(bodyParser.json());
//Middleware to log all requests to the server for debugging
app.use((req, res, next) => {
console.log(`--->
${req.method} ${req.url}`);
next(); // Pass control to the next middleware function
});
// const apiSpecPath = path.join(process.cwd(), "openapi.yml");
// app.use(
// OpenApiValidator.middleware({
// apiSpec: apiSpecPath,
// validateRequests: false, // (default)
// validateResponses: false, // false by default
// // ignorePaths: [/^\/offer-code-sd-jwt$/, /^\/offer-no-code$/, /^\/offer-tx-code$/],
// })
// );
app.use("/", router);
app.use("/", verifierRouter);
app.use("/", metadataRouter);
app.use("/", codeFlowRouter);
app.use("/", codeFlowRouterSDJWT);
app.use("/", pidRouter);
app.use("/", passportRouter);
app.use("/", educationalRouter);
app.use("/", boardingPassRouter);
app.use("/", didWebRouter);
// Error handler for validation errors
app.use((err, req, res, next) => {
// Format error response
res.status(err.status || 500).json({
message: err.message,
errors: err.errors,
});
});
// Start the server
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});