Introducing Snake Server, a simple local web server for Haxe

Hi, Haxe community! I’d like to introduce :snake: snake-server :snake:, a simple local web server created for Haxe developers targeting JS.

haxelib install snake-server
haxelib run snake-server

Run a local development server in any directory to serve static files. Doesn’t rely on another language’s tooling, like Node.js, Python, etc. Pure Haxe using sys.net.Socket.

Blog post with more details:
https://joshblog.net/2024/introducing-snake-server-a-simple-local-web-server-for-haxe/

9 Likes

Hi Josh,

(I haven’t tried this out yet, but intend to soon)

First off, thanks for putting this together. Like you, it irks me a tiny bit that I need Python for my Haxe projects.

I do want to ask: do you see this project remaining very tightly scoped as “serve the html (or other files) from this directory”, or would you consider it as (say) a replacement for something a tad bigger, like node’s Express?

-Rahul

The snake-server project is definitely intended to strictly serve files from a local directory only. I saw that the http.server Python module that its code was ported from had another subclass that supported CGI, so in theory, an API to make servers like Express is technically possible. However, that CGI subclass was recently deprecated, so it seems like Python is also purposefully trying to keep the scope of the module small.

Additionally, Python’s documentation for its http.server module has a pretty big warning at the top:

Warning: http.server is not recommended for production. It only implements basic security checks.

With all that in mind, making it into something you can build an Express-like library on top of isn’t a priority for me. I’m not really a backend developer, so hardening things to be production-ready is outside of my area of expertise.

I should add that I also briefly considered porting Node’s http module to Haxe. It looks like it is written in JavaScript, so the code seems like it would be high-level and relatively straightforward to port to another language like Haxe. It would probably be much harder if it were C/C++ instead, with all of its manual memory management and things. A port of Node’s http module would make a better base for an Express-like library, in my opinion.

I know that haxe already has a simple server called nekotools server,
but its API seems to have been deprecated (hx4compat::neko.Web)