godprotocol 2.2.60 → 2.2.62

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "godprotocol",
3
- "version": "2.2.60",
3
+ "version": "2.2.62",
4
4
  "description": "A distributed computing environment for Web 4.0 — integrating AI, decentralisation, and virtual computation.",
5
5
  "main": "Index.js",
6
6
  "type": "module",
@@ -21,6 +21,23 @@ const getBody = (req) => {
21
21
  });
22
22
  };
23
23
 
24
+ const applyCors = (req, res) => {
25
+ res.setHeader("Access-Control-Allow-Origin", "*");
26
+
27
+ res.setHeader(
28
+ "Access-Control-Allow-Methods",
29
+ "GET, POST, PUT, PATCH, DELETE, OPTIONS",
30
+ );
31
+
32
+ res.setHeader(
33
+ "Access-Control-Allow-Headers",
34
+ "Content-Type, Authorization, x-api-version, x-api-key, x-platform",
35
+ );
36
+
37
+ // IMPORTANT: do NOT enable credentials with "*"
38
+ // res.setHeader("Access-Control-Allow-Credentials", "true");
39
+ };
40
+
24
41
  const respond = (result, res) => {
25
42
  const response = {
26
43
  ok: result?.ok ?? false,
@@ -42,6 +59,13 @@ const respond = (result, res) => {
42
59
 
43
60
  const version_middleware = async (req, res, routers) => {
44
61
  try {
62
+ applyCors(req, res);
63
+
64
+ if (req.method === "OPTIONS") {
65
+ res.statusCode = 204;
66
+ return res.end();
67
+ }
68
+
45
69
  const version = req.headers["x-api-version"] || "v1";
46
70
 
47
71
  const versionRouter = routers.get_version(version);
@@ -52,6 +76,7 @@ const version_middleware = async (req, res, routers) => {
52
76
 
53
77
  if (!versionRouter) {
54
78
  res.statusCode = 400;
79
+ res.setHeader("Content-Type", "application/json");
55
80
  return res.end(
56
81
  JSON.stringify({
57
82
  ok: false,
@@ -123,6 +148,7 @@ const version_middleware = async (req, res, routers) => {
123
148
  console.error("Version Middleware Error:", err);
124
149
 
125
150
  res.statusCode = 500;
151
+ res.setHeader("Content-Type", "application/json");
126
152
  res.end(
127
153
  JSON.stringify({
128
154
  ok: false,