As dev7060 said that is one approach and probably the easiest if you are already familiar with a web-programming language that has functions that can execute code on the server.
Another is to use Web Assembly also known as WASM.
It really comes down to your existing code-base, your ability and the need for application to perform.
What is Web Assembly?
Web Assembly is a specification for a virtual machine that runs in the browser. Compared to the highly dynamic JavaScript, Web Assembly can achieve much higher performance. Contrary to popular misconception though, Web Assembly doesn't completely replace JavaScript. You will probably use the two together. Web Assembly is based on LLVM (Low Level Virtual Machine), a stack based virtual machine that compilers can target.
Why use it?
Typically, when people talk about the advantages of WebAssembly, it’s from the standpoint of performance. But WebAssembly brings another advantage to the table—code reuse. Rather than writing the same logic multiple times for each target environment (desktop, website, and others), WebAssembly lets you reuse the same code in multiple locations.
Here's a
doc on dev.mozilla that helps setup a basic C++ module to Web Assembly.
The jist of it is:
Compiling C++ code into Web Assembly using (
Emscripten )
Emscriptem is a LLVM to JS compiler which results in
- The binary wasm module code (hello.wasm)
- A JavaScript file containing glue code to translate between the native C functions, and JavaScript/wasm (hello.js)
- An HTML file to load, compile, and instantiate your wasm code, and display its output in the browser (hello.html)
Call the HTML file in a browser that supports Web Assembly
- Web assembly is enabled by default in Firefox 52+ and Chrome 57+/latest Opera
- You can also run wasm code in Firefox 47+ by enabling the javascript.options.wasm flag in about:config
- Chrome (51+) and Opera (38+) by going to chrome://flags and enabling the Experimental WebAssembly flag.
Some intriguing points about both methods.
Server:
- Security - because it's server code, the inputs should be strictly validated and contained to keep arbitrary from code executing on your server.
- Server Performance - also it might have an effect on the performance of other users of your service depending on if you run as a service or execute on demand.
Web Assembly ( Client ):
- Local performance - test it for performance on various machines before deploying it ( memory leaks etc )
- Security - It's contained in a VM on the client browser, regardless input should be validated.
- Feature access - The compiled WASM binaries will have access to the same features that the browser has on the client machine.
Other languages that WASM supports
- C/C++
- C#/.NET
- Elixir
- Go
- Java
- Python
- Rust
References:
Compiling a New C/C++ Module to WebAssembly Introduction to Web Assembly with C/C++ Reusing your existing C++ codebase Emscripten - compiler toolchain to WebAssembly, using LLVM.