[dev utility] Node.js HTTP wrapper

A quick HTTP wrapper to allow you to use HTTP frameworks like Koa (or similar frameworks, excluding Express) in FXServer Node.js resources.

Usage

$ mkdir -p resources/[local]/koan
$ cd resources/[local]/koan
$ yarn init
$ yarn add @citizenfx/http-wrapper koa
$ cat > __resource.lua <<EOF
server_script 'server.js'
dependency 'yarn'
EOF
$ cat > server.js <<EOF
const { setHttpCallback } = require('@citizenfx/http-wrapper');
const Koa = require('koa');

const app = new Koa();
app.use(async ctx => {
	ctx.body = 'Hello World!'
});

// instead of app.listen()
setHttpCallback(app.callback());
EOF
cfx> refresh
cfx> start koan
http://localhost:30120/koan/
11 Likes

Sexy af :stuck_out_tongue:

cool


20 chr

1 Like

interesting…might have to take a second look on that

:frowning: Y no Express?
20 Char

Express doesn’t support other implementations of ServerResponse/IncomingMessage than the ones in http, this was meant to be fixed for Express 5 in 2015 but since Express doesn’t seem to be maintained anymore it’s still unfixed.

1 Like

can someone put a picture something I do not know what it is with this script