Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added web app demo #55

Merged
merged 20 commits into from
Nov 9, 2024
Merged

Added web app demo #55

merged 20 commits into from
Nov 9, 2024

Conversation

sidi762
Copy link
Contributor

@sidi762 sidi762 commented Nov 3, 2024

Added a new web app demo

Work in Progress

Todo:

  • Implement execution time limit (maybe also memory limit?) to prevent infinite loops and attacks

Add Web Interface for Nasal Interpreter

This PR adds a web-based interface for the Nasal Interpreter, allowing users to write and execute Nasal code directly in their browser.

Implementation

Web Interpreter

  • Added Node.js web server using Express
  • Created C++ bindings using ffi-napi to interface with the Nasal interpreter
  • Implemented nasal-web shared library for interpreter integration
  • Used CodeMirror for the code editor
  • Added proper error handling and output capturing
  • Implemented ANSI color code conversion for error messages

Web REPL

  • Interactive command-line style interface in the browser
  • Multi-line input support with proper prompts (>>> and ...)
  • Command history navigation (up/down arrow keys)
  • Error handling with formatted error messages
  • Example snippets for quick testing
  • Clear screen functionality
  • Auto-resizing input field

Files Added/Modified

  • /nasal-web-app/ - New directory containing the web application
    • server.js - Express server implementation
    • server_repl.js - REPL server demo
    • public/index.html - Main web interface
    • public/repl.html - REPL UI
    • public/repl.js - REPL implementation
    • package.json - Node.js dependencies
  • src/nasal_web.cpp - C++ bindings for the Nasal interpreter
  • src/nasal_web.h - Header file for C++ bindings
  • CMakeLists.txt - Updated to build the shared library
  • .gitignore - Updated for Node.js and web app files

Build Instructions

  1. Build the Nasal shared library:
cmake -DBUILD_SHARED_LIBS=ON .
make nasal-web
  1. Set up and run the web application:

Web Interpreter

cd nasal-web-app
npm install
node server.js

and visit

http://127.0.0.1:3000/

Web REPL

cd nasal-web-app
npm install
node server_repl.js

and visit

http://127.0.0.1:3001/repl.html

src/nasal_web.cpp Outdated Show resolved Hide resolved
@sidi762 sidi762 marked this pull request as draft November 4, 2024 17:38
@sidi762 sidi762 marked this pull request as ready for review November 9, 2024 05:58
@sidi762 sidi762 changed the title [WIP] Added web app demo Added web app demo Nov 9, 2024
@ValKmjolnir ValKmjolnir merged commit 0e85bfc into ValKmjolnir:master Nov 9, 2024
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants