로컬 C++ 채점 서버. data.json 기반의 JSON HTTP API.
- Node.js 18+
- npm
g++(C++ 컴파일러)
윈도우에서는 MinGW-w64/MSYS2의 g++를 권장합니다. g++가 PATH에 없다면 서버 실행 전에 컴파일러 경로를 지정할 수 있습니다.
$env:JUDGE_CXX="C:\msys64\ucrt64\bin\g++.exe"
$env:JUDGE_COMPILE_TIMEOUT_MS="30000"
$env:HOST="0.0.0.0"
$env:PORT="12014"
npm start- Windows 기본 컴파일 제한은 MinGW/MSYS2 지연을 고려해 30초입니다.
- 사용자명/Temp 경로에 한글·공백이 있어
g++가 파일을 못 여는 경우, 서버는 자동으로 프로젝트의.judge-tmp를 우선 사용합니다. 필요하면$env:JUDGE_TEMP_ROOT="C:\judge-tmp"처럼 직접 지정할 수 있습니다. - 복사한 해설 코드에 붙은 Markdown 코드블록 fence, BOM, NBSP 같은 보이지 않는 문자는 컴파일 전 안전하게 정리됩니다.
language가C++20/gnu++20이면-std=gnu++20, 기본값은 BOJ와 가까운-std=gnu++17입니다.
npm installHOST=0.0.0.0 PORT=12014 npm start- 로컬:
http://127.0.0.1:12014 - 헬스체크:
GET /health
curl http://127.0.0.1:12014/
# {"ok":true,"service":"judge_server","endpoints":{"health":"/health","judge":"/judge"}}
curl http://127.0.0.1:12014/health
# {"ok":true,"service":"judge_server"}curl -sS -X POST http://127.0.0.1:12014/judge \
-H 'content-type: application/json' \
--data-binary @- <<'JSON'
{
"problemId": 1000,
"sourceCode": "#include <bits/stdc++.h>\nusing namespace std;\nint main(){ long long a,b; cin>>a>>b; cout << a+b << \"\\n\"; }\n",
"testCases": [
{ "input": "1 2\n", "output": "3\n" }
],
"timeLimit": "1 초",
"memoryLimit": "128 MB"
}
JSON코딩살구 웹 클라이언트 호환을 위해 같은 배열을 samples 필드로 보내도 채점합니다.
curl -sS -X POST http://127.0.0.1:12014/judge \
-H 'content-type: application/json' \
--data-binary @data.json > ret.json# 포어그라운드: Ctrl+C
# 백그라운드:
lsof -tiTCP:12014 -sTCP:LISTEN | xargs killnpm test # 문법 체크
npm run smoke # /health 검증
JUDGE_URL=http://127.0.0.1:12014 npm run smokehttp://127.0.0.1:3100http://localhost:3100https://cosal.aviss.kr
Preflight 확인:
curl -i -X OPTIONS http://127.0.0.1:12014/judge \
-H 'Origin: https://cosal.aviss.kr' \
-H 'Access-Control-Request-Method: POST' \
-H 'Access-Control-Request-Headers: content-type'→ 204 No Content + access-control-allow-origin 헤더 반환되면 정상.
{ "ok": true, "status": "ok", "service": "judge04", "problemId": 2468, "testCount": 8 }요청:
{ "sourceCode": "#include <bits/stdc++.h>\nint main(){return 0;}\n" }sourceCode 생략 시 data.json.sourceCode 사용.
응답:
{
"ok": true,
"verdict": "AC",
"problemId": 2468,
"summary": { "passed": 8, "total": 8 },
"compile": { "exitCode": 0, "stdout": "", "stderr": "" },
"cases": [
{
"index": 1,
"status": "AC",
"input": "...",
"expected": "...",
"actual": "...",
"stderr": "",
"runtimeMs": 12,
"exitCode": 0
}
]
}에러:
{ "ok": false, "error": { "code": "ERROR_CODE", "message": "..." } }| 코드 | 의미 |
|---|---|
AC |
Accepted |
WA |
Wrong Answer |
CE |
Compile Error |
RE |
Runtime Error |
TLE |
Time Limit Exceeded |