This is the compiler API for the HandsOnCoding project, an open-source MOOC (Massive Open Online Courses) for multiple programming languages.
In order to run this project you should install Node in your computer.
Is recomended to use and install Docker Desktop to run the project with all the needed dependecies in a secure enviroment.
- Clone the repository
git clone https://github.com/mavaldot/pdg-compiler
- Go inside the project folder
cd HandsOnCoding-Back
- Install npm packages (if you are going to run without Docker)
npm i
Code | Meaning |
---|---|
-1 | Internal Error |
10 | Compiled correctly |
11 | Syntax error |
20 | Shell error |
21 | Compilation error |
30 | Timed Out |
40 | Request error |
50 | Invalid language |
Script | Description |
---|---|
test | Run mocha tests |
start | Start the app |
Run the scripts with the command:
npm run <script>
This project runs JavaScript, Python, and C++ code, but you can also define more languages in the data/languages.js file. You only need to add the language in the json variable as follows:
{
"python": {
"filename": "main.py",
"command": "python3 main.py < input.txt"
}
}
To run the service, just execute the command:
npm start
If you want to use Docker, open Docker Desktop and run this commands instead:
docker build -t comserver .
docker run -p 12345:12345 comserver
In both cases, the service will be running at http://localhost:12345/.
To run the tests, use the following command:
npm start test
To auto-generate an HTML file from the Swagger specs (generated every time you run the app in the "docs" folder), you need to install the global dependencies:
npm install -g redoc-cli
and run the following command from the root folder:
redoc-cli build -o docs/swagger.html docs/swagger.json
Just do a POST request to the base URL with a JSON file with the following structure:
{
"language": "python",
"code": "print(input())"
"input": "Hello World!"
}
and you will receive a similar JSON file:
{
"code": 10
"msg": "Hello World!\n"
}
For more information visit the Compiler API Doc.