Hey :). As part of building an open source stack for everybody to witness the wonder that is Haxe, I’m working at a Node JS Express server (complete with watchers, debug via VS Code, source maps integrated in the error reports in the console and more).
For the past few hours I’ve been tinkering at getting CORS to work with Express. I’ve been using @haxiomic 's dts2hx to generate the externs for both Express and CORS. Express worked fine, but I got stuck with CORS.
I think dts2hx doesn’t completely process the cors
package. The .ts files have a namespace declaration called “e”. dts2hx does extract the members in the namespace, but only at a “root level” so to say. It also misses a critical function needed to wire up cors
to Express.
The function is at the end of the node_modules\@types\cors\index.d.ts
file:
//the rest of the file...
declare function e(
options?: e.CorsOptions | e.CorsOptionsDelegate
): express.RequestHandler;
export = e;
And this is missing in the Haxe extern. So…
I’ve been working at declaring an extern for this e
. I haven’t wrote a single extern before, but I do understand the principles of it. So, I did /some/ work.
But now I need a pointer regarding how would one create an extern for a JS function that is located outside of a class.
This is the class I’ve added to the cors
dts2hx-generated package:
And this is how I’m trying to use it, of course, trying to hook it in the Express middleware by using app.use()
Of course, this can’t work anyway because I created the class as HowToMapThis
, because I don’t know how to reach that e
function
Oh, and if you want to actually run the project and work directly on it, see the readme.md in the repo root