Giter Club home page Giter Club logo

wicon2021 / code-editor Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dakshesh14/code-editor

0.0 0.0 0.0 763 KB

Seamlessly write Python, C++, JavaScript, Java, and React code in your browser, with instant output. While React operates directly on the browser, the rest execute securely on isolated servers.

Home Page: https://www.dakshesh.me/projects/online-code-editor-35016a55

JavaScript 0.63% Python 30.12% TypeScript 69.02% CSS 0.10% Dockerfile 0.13%

code-editor's Introduction

Code-editor

An online code-editor, where you can write python, cpp, javascript, java, and react code in your browser and see the output in the same window. Except for react, all other languages are executed on the server-side in an isolated environment to ensure security.

I covered interpreter language, compile language and client side technology in this project to demonstrate how might one handle these languages.

For.Github.Readme.mp4

Features

  • Write & execute python, cpp, javascript, java, and react code in your browser.
  • Create files and folders inside your project.
  • Isolated environment to execute code ensuring security and resource management.
  • Limit execution time and memory usage.
  • Uses monaco editor to give user a look and feel they are already familiar with.
  • Uses fingerprint to authenticate users (of-course don't use this in production).
  • Uses docker to create isolated environment.

How to run

Assuming you have docker, yarn, python3, and node installed on your system.

  • Clone the repo
git clone
  • Install dependencies for server
cd apiserver
pip install -r requirements.txt
  • Install dependencies for client
cd app
yarn install
  • Setup docker image
cd apiserver
docker build -t code-editor:latest .
  • Run the server
cd apiserver
python3 manage.py runserver
  • Run the client
cd app
yarn start

Screenshots

screenshot 1 screenshot 2 screenshot 3

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. I would love to hear your feedback and suggestions. I have also created a lot of issues for this project, feel free to pick one and start working on it.

Topics

Without going into too much implementation detail, I will try to explain how I handled different aspects of this project.

Authentication

I used fingerprint to generate a unique fingerprint for each user. This fingerprint is then used to authenticate the user. I know this is not the best way to authenticate users, but I wanted to keep things simple, since this project will be only used for demonstration purposes.

To generate fingerprint I used fingerprintjs on the client-side. I store fingerprint in cookies and send it with each request in the header.

I also made a custom middleware to authenticate users using fingerprint and append user object to the request object.

Isolated environment

I used docker to create an isolated environment for each execution. I created a docker image with all the dependencies installed. I then used this image to create a container for each execution. I used py-docker to interact with docker. You could also configure docker to also host your application.

Limit execution time and memory usage

To set a limit on system calls and resource usage, I have configured docker to use seccomp profile for system calls and have enforced resource using ulimit. Depending on your use case and the language you are executing, you might want to configure these settings. I will recommend you to start with the least resource & permission and then add more as you need.

Code editor

I used monaco editor to give users a look and feel they are already familiar with. I also added some customizations to make it more user friendly.

Socials

Acknowledgement

Future scope

Apart from the issues I have created, there are a lot of things that can be done to improve this project. Some of them are:

  • Add support for environment variables for code execution.
  • Making the editor collaborative using websockets & CRDT.
  • Add support for more languages.
  • Add support for more frameworks.

code-editor's People

Contributors

dakshesh14 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.