TooTallNate / fetch-server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Deploy to a Vercel API endpoint:

// api/hello.ts

import fetchServer from 'fetch-server';

export default fetchServer(async req => {
    console.log(req.url);
    console.log(req.headers.get('x-custom'));

    return Response.json({ hello: 'world' });
});

Standalone:

// server.ts

import http from 'node:http';
import fetchServer from 'fetch-server';

const server = http.createServer(fetchServer(async req => {
    console.log(req.url);
    console.log(req.headers.get('x-custom'));

    return Response.json({ hello: 'world' });
}));

server.listen(3000);

About


Languages

Language:TypeScript 100.0%