Second frontend, written in Next.JS + Typescript.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

1 lines
5.8 KiB

{"ast":null,"code":"import _regeneratorRuntime from \"@babel/runtime/regenerator\";\nimport _defineProperty from \"@babel/runtime/helpers/esm/defineProperty\";\n\nfunction ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }\n\nfunction _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }\n\nimport fetch from \"node-fetch\";\nimport { getSession } from \"next-auth/client\";\nimport config from \"../config\";\nexport default function post(req, res) {\n var authHeaders, session, apires;\n return _regeneratorRuntime.async(function post$(_context) {\n while (1) {\n switch (_context.prev = _context.next) {\n case 0:\n if (!(req.method !== \"POST\")) {\n _context.next = 3;\n break;\n }\n\n res.status(405).json({\n error: \"Method not allowed;.\"\n });\n return _context.abrupt(\"return\");\n\n case 3:\n if (!(typeof req.body !== \"object\" || typeof req.body.query !== \"string\")) {\n _context.next = 6;\n break;\n }\n\n res.status(400).json({\n error: \"Invalid request body (expected json object with query)\"\n });\n return _context.abrupt(\"return\");\n\n case 6:\n authHeaders = {};\n _context.next = 9;\n return _regeneratorRuntime.awrap(getSession({\n req: req\n }));\n\n case 9:\n session = _context.sent;\n\n if (session != null && session.user != null) {\n authHeaders[\"Authorization\"] = \"Bearer \".concat(config.jwtToken(session.user.name, 15));\n }\n\n _context.next = 13;\n return _regeneratorRuntime.awrap(fetch(config.apiUrl(\"/graphql\"), {\n method: \"POST\",\n headers: _objectSpread({\n \"Content-Type\": \"application/json\"\n }, authHeaders),\n body: JSON.stringify(req.body)\n }));\n\n case 13:\n apires = _context.sent;\n res.setHeader(\"Content-Type\", apires.headers.get(\"Content-Type\"));\n res.status(apires.status);\n apires.body.pipe(res);\n\n case 17:\n case \"end\":\n return _context.stop();\n }\n }\n }, null, null, null, Promise);\n}","map":{"version":3,"sources":["/data/projects/react/rpdata-frontend2/pages/graphql.ts"],"names":["fetch","getSession","config","post","req","res","method","status","json","error","body","query","authHeaders","session","user","jwtToken","name","apiUrl","headers","JSON","stringify","apires","setHeader","get","pipe"],"mappings":";;;;;;;AAAA,OAAOA,KAAP,MAAkB,YAAlB;AAEA,SAASC,UAAT,QAA2B,kBAA3B;AAEA,OAAOC,MAAP,MAAmB,WAAnB;AAEA,eAAe,SAAeC,IAAf,CAAoBC,GAApB,EAAyCC,GAAzC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBACTD,GAAG,CAACE,MAAJ,KAAe,MADN;AAAA;AAAA;AAAA;;AAEXD,UAAAA,GAAG,CAACE,MAAJ,CAAW,GAAX,EAAgBC,IAAhB,CAAqB;AAACC,YAAAA,KAAK,EAAE;AAAR,WAArB;AAFW;;AAAA;AAAA,gBAMT,OAAOL,GAAG,CAACM,IAAX,KAAqB,QAArB,IAAiC,OAAON,GAAG,CAACM,IAAJ,CAASC,KAAhB,KAA2B,QANnD;AAAA;AAAA;AAAA;;AAOXN,UAAAA,GAAG,CAACE,MAAJ,CAAW,GAAX,EAAgBC,IAAhB,CAAqB;AAACC,YAAAA,KAAK,EAAE;AAAR,WAArB;AAPW;;AAAA;AAWPG,UAAAA,WAXO,GAWO,EAXP;AAAA;AAAA,2CAYSX,UAAU,CAAC;AAACG,YAAAA,GAAG,EAAHA;AAAD,WAAD,CAZnB;;AAAA;AAYPS,UAAAA,OAZO;;AAab,cAAIA,OAAO,IAAI,IAAX,IAAmBA,OAAO,CAACC,IAAR,IAAgB,IAAvC,EAA6C;AAC3CF,YAAAA,WAAW,CAAC,eAAD,CAAX,oBAAyCV,MAAM,CAACa,QAAP,CAAgBF,OAAO,CAACC,IAAR,CAAaE,IAA7B,EAAmC,EAAnC,CAAzC;AACD;;AAfY;AAAA,2CAiBQhB,KAAK,CAACE,MAAM,CAACe,MAAP,CAAc,UAAd,CAAD,EAA4B;AACpDX,YAAAA,MAAM,EAAE,MAD4C;AAEpDY,YAAAA,OAAO;AACL,8BAAgB;AADX,eAEFN,WAFE,CAF6C;AAMpDF,YAAAA,IAAI,EAAES,IAAI,CAACC,SAAL,CAAehB,GAAG,CAACM,IAAnB;AAN8C,WAA5B,CAjBb;;AAAA;AAiBPW,UAAAA,MAjBO;AA0BbhB,UAAAA,GAAG,CAACiB,SAAJ,CAAc,cAAd,EAA8BD,MAAM,CAACH,OAAP,CAAeK,GAAf,CAAmB,cAAnB,CAA9B;AACAlB,UAAAA,GAAG,CAACE,MAAJ,CAAWc,MAAM,CAACd,MAAlB;AACAc,UAAAA,MAAM,CAACX,IAAP,CAAYc,IAAZ,CAAiBnB,GAAjB;;AA5Ba;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["import fetch from \"node-fetch\";\nimport { NextApiRequest, NextApiResponse } from \"next\";\nimport { getSession } from \"next-auth/client\";\n\nimport config from \"../config\";\n\nexport default async function post(req: NextApiRequest, res: NextApiResponse) {\n if (req.method !== \"POST\") {\n res.status(405).json({error: \"Method not allowed;.\"});\n return;\n }\n \n if (typeof(req.body) !== \"object\" || typeof(req.body.query) !== \"string\") {\n res.status(400).json({error: \"Invalid request body (expected json object with query)\"});\n return;\n }\n\n const authHeaders = {};\n const session = await getSession({req});\n if (session != null && session.user != null) {\n authHeaders[\"Authorization\"] = `Bearer ${config.jwtToken(session.user.name, 15)}`;\n }\n\n const apires = await fetch(config.apiUrl(\"/graphql\"), {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...authHeaders,\n },\n body: JSON.stringify(req.body),\n });\n\n res.setHeader(\"Content-Type\", apires.headers.get(\"Content-Type\"));\n res.status(apires.status);\n apires.body.pipe(res);\n}\n"]},"metadata":{},"sourceType":"module"}