godprotocol 2.2.60 → 2.2.61

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.61",
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,8 @@ const respond = (result, res) => {
42
59
 
43
60
  const version_middleware = async (req, res, routers) => {
44
61
  try {
62
+ applyCors(req, res);
63
+
45
64
  const version = req.headers["x-api-version"] || "v1";
46
65
 
47
66
  const versionRouter = routers.get_version(version);
@@ -52,6 +71,7 @@ const version_middleware = async (req, res, routers) => {
52
71
 
53
72
  if (!versionRouter) {
54
73
  res.statusCode = 400;
74
+ res.setHeader("Content-Type", "application/json");
55
75
  return res.end(
56
76
  JSON.stringify({
57
77
  ok: false,
@@ -123,6 +143,7 @@ const version_middleware = async (req, res, routers) => {
123
143
  console.error("Version Middleware Error:", err);
124
144
 
125
145
  res.statusCode = 500;
146
+ res.setHeader("Content-Type", "application/json");
126
147
  res.end(
127
148
  JSON.stringify({
128
149
  ok: false,