-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Matteo Collina <[email protected]>
- Loading branch information
Showing
12 changed files
with
91 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict' | ||
|
||
module.exports = require('neostandard')({}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
"description": "An Undici interceptor that routes requests over a worker thread", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "node --test test/*.test.js" | ||
"test": "eslint && borp --coverage" | ||
}, | ||
"keywords": [ | ||
"undici", | ||
|
@@ -15,14 +15,17 @@ | |
"author": "Matteo Collina <[email protected]>", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"borp": "^0.15.0", | ||
"express": "^4.19.2", | ||
"fastify": "^4.27.0", | ||
"fastify-undici-dispatcher": "^0.6.0", | ||
"koa": "^2.15.3" | ||
}, | ||
"dependencies": { | ||
"eslint": "^9.5.0", | ||
"hyperid": "^3.2.0", | ||
"light-my-request": "^5.13.0", | ||
"neostandard": "^0.7.2", | ||
"undici": "^6.18.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,44 @@ | ||
'use strict' | ||
|
||
const { test } = require('node:test') | ||
const { deepStrictEqual, strictEqual } = require('node:assert') | ||
const { deepStrictEqual } = require('node:assert') | ||
const { join } = require('path') | ||
const { Worker } = require('worker_threads') | ||
const { createThreadInterceptor } = require('../') | ||
const { Agent, request } = require('undici') | ||
|
||
test('express', async (t) => { | ||
test('express', async (t) => { | ||
const worker = new Worker(join(__dirname, 'fixtures', 'express1.js')) | ||
t.after(() => worker.terminate()) | ||
|
||
const interceptor = createThreadInterceptor({ | ||
domain: '.local' | ||
domain: '.local', | ||
}) | ||
interceptor.route('myserver', worker) | ||
|
||
const agent = new Agent().compose(interceptor) | ||
|
||
const { body, headers } = await request('http://myserver.local',{ | ||
dispatcher: agent | ||
const { body } = await request('http://myserver.local', { | ||
dispatcher: agent, | ||
}) | ||
|
||
deepStrictEqual(await body.json(), { hello: 'world' }) | ||
}) | ||
|
||
test('koa', async (t) => { | ||
test('koa', async (t) => { | ||
const worker = new Worker(join(__dirname, 'fixtures', 'koa1.js')) | ||
t.after(() => worker.terminate()) | ||
|
||
const interceptor = createThreadInterceptor({ | ||
domain: '.local' | ||
domain: '.local', | ||
}) | ||
interceptor.route('myserver', worker) | ||
|
||
const agent = new Agent().compose(interceptor) | ||
|
||
const { body, headers } = await request('http://myserver.local',{ | ||
dispatcher: agent | ||
const { body } = await request('http://myserver.local', { | ||
dispatcher: agent, | ||
}) | ||
|
||
deepStrictEqual(await body.json(), { hello: 'world' }) | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
'use strict' | ||
|
||
const { parentPort, workerData } = require('worker_threads') | ||
const { parentPort, workerData } = require('worker_threads') | ||
const Koa = require('koa') | ||
const { wire } = require('../../') | ||
|
||
const app = new Koa() | ||
|
||
app.use(ctx => { | ||
ctx.body = { hello: workerData?.message || 'world' } | ||
}); | ||
}) | ||
|
||
wire(app.callback(), parentPort) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
'use strict' | ||
|
||
const { parentPort, workerData } = require('worker_threads') | ||
const { parentPort } = require('worker_threads') | ||
const fastify = require('fastify') | ||
const { wire, createThreadInterceptor } = require('../../') | ||
const { request, agent } = require('undici') | ||
const { wire } = require('../../') | ||
const { request } = require('undici') | ||
|
||
const app = fastify() | ||
|
||
wire(app, parentPort, { | ||
domain: '.local' | ||
domain: '.local', | ||
}) | ||
|
||
app.get('/', async (req, reply) => { | ||
const { body, headers } = await request('http://myserver.local') | ||
app.get('/', async (req, reply) => { | ||
const { body } = await request('http://myserver.local') | ||
return await body.json() | ||
}) | ||
|
Oops, something went wrong.