Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
trpc-bun-adapter
Advanced tools
Leverage TRPC on Bun with ease.
Supports both HTTP and WebSockets transports.
Install the package:
bun install @trpc/server trpc-bun-adapter
Paste the following code into server.ts
:
import {createBunServeHandler} from 'trpc-bun-adapter';
import {router} from './router';
Bun.serve(createBunServeHandler({ router }));
Run the server with HTTP and WebSocket transports:
bun run server.ts
Creates a Bun serve handler for HTTP and WebSocket transports:
import {createBunServeHandler} from 'trpc-bun-adapter';
import {router} from './router';
const createContext = (opts: { req: Request }) => ({
user: 1,
});
Bun.serve(
createBunServeHandler(
{
router,
// optional arguments:
endpoint: '/trpc', // Default to ""
createContext,
onError: console.error,
responseMeta(opts) {
return {
status: 202,
headers: {},
}
},
batching: {
enabled: true,
},
},
{
// Bun serve options
port: 3001,
fetch(request, server) {
// will be fired if it's not a TRPC request
return new Response("Hello world");
},
},
),
);
Arguments are:
options
- TRPC optionsbunOptions
- Bun serve optionsCreates a Bun HTTP handler for HTTP transport:
import {createBunHttpHandler} from 'trpc-bun-adapter';
import {router} from './router';
const createContext = (opts: { req: Request }) => ({
user: 1,
});
const bunHandler = createBunHttpHandler({
router,
// optional arguments:
endpoint: '/trpc', // Default to ""
createContext,
onError: console.error,
responseMeta(opts) {
return {
status: 202,
headers: {},
}
},
batching: {
enabled: true,
},
emitWsUpgrades: false, // pass true to upgrade to WebSocket
});
Bun.serve({
fetch(request, response) {
return bunHandler(request, response) ?? new Response("Not found", {status: 404});
}
});
Creates a Bun WebSocket handler for WebSocket transport:
import {ServerWebSocket} from "bun";
import {createBunWSHandler, BunWSClientCtx} from './src';
import {router} from './router';
const createContext = (opts: { req: Request, client: ServerWebSocket<BunWSClientCtx> }) => ({
user: 1,
});
const websocket = createBunWSHandler({
router,
// optional arguments:
createContext,
onError: console.error,
batching: {
enabled: true,
},
});
Bun.serve({
fetch(request, server) {
if (server.upgrade(request, {data: {req: request}})) {
return;
}
return new Response("Please use websocket protocol", {status: 404});
},
websocket,
});
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Feel free to open issues and pull requests.
FAQs
TRPC adapter for bun js runtime
The npm package trpc-bun-adapter receives a total of 612 weekly downloads. As such, trpc-bun-adapter popularity was classified as not popular.
We found that trpc-bun-adapter demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.