当多个用户同时发送 POST 请求时,代理服务器发送相同的响应 Sphere-engine Api 的代理服务器

问题描述

我正在使用 sphere 引擎编译器 API 构建一个 Online Code editor for Java

我使用 Sphere Engine Compilers APIExpress 创建了一个代理服务器。并使用此代理服务器在客户端(前端)获取数据(编译后的程序输出)。但是当多个用户同时向代理服务器发送 post 请求时,所有用户都从代理服务器得到相同的响应。

const express = require("express");
const cors = require("cors");
require('dotenv').config();
const fetch = require('node-fetch');
const Bluebird = require('bluebird');
fetch.Promise = Bluebird;
var accesstoken = process.env.ACCEsstOKEN ;
var endpoint = process.env.ENDPOINT;
var stream,submissionId;
const app = express();
const PORT=process.env.PORT;
app.use(express.json());
app.use(cors());


app.get('/',(req,res)=>{
    console.log("Got a request");
   res.send("Hello User!");
});

app.post('/api/compiler/java',res)=>{  
fetch('https://' + endpoint + '/api/v4/submissions?access_token=' + accesstoken,{
   method: 'POST',mode: "no-cors",headers: {
     'Content-Type': 'application/json',},body: JSON.stringify(req.body),})
 .then(response => response.json())
 .then( data => {
   console.log('Success:',data);
   submissionId=  data.id;
 })
 .catch((error) => {
   console.error('Error:',error);
 });
 
 
  
 setTimeout(() => {
     fetch('https://' + endpoint + '/api/v4/submissions/' + submissionId +  '?access_token=' + accesstoken)
 .then(res=>res.json())
 .then(response => {
   // console.log('Success:',response.result);
   var out= response.result.streams;
   if(out.output){stream='output'}
   else if(out.cmpinfo){stream='cmpinfo'}
   else if(out.error){stream='error'}
 
   console.log(stream);
 })
 .catch((error) => {
   console.error('Error:',error);
 }).then(()=>{
     fetch('https://' + endpoint + '/api/v4/submissions/' + submissionId + '/'+stream+ '?access_token=' + accesstoken)
 .then(res=>res.text())
 .then(response => {
  console.log('Success:',response);
   res.send(response);
 })
 .catch((error) => {
   console.error('Error:',error);
 }); })
 },5000);  
   
});


app.listen(process.env.PORT,()=>console.log(`server is listening on port:${PORT}`));  
快照:1

enter image description here

快照:2

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...