Skip to content

Commit

Permalink
Change version
Browse files Browse the repository at this point in the history
  • Loading branch information
aquapi committed May 23, 2024
1 parent 99e84e3 commit 9b543f0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bit-js/byte",
"version": "1.3.7",
"version": "1.3.8",
"module": "index.js",
"devDependencies": {
"@types/bun": "latest",
Expand Down
32 changes: 28 additions & 4 deletions src/core/server/types/handler.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,37 @@
import { Context as TypedContext, type Params } from '@bit-js/blitz';
import type { Params } from '@bit-js/blitz';
import type { BasicResponse, JsonResponse, NullableBody } from '../utils/responses';
import type { CommonHeaders, CommonResponseInit } from '../types/responseInit';

// Base context
export class Context<Params, State = undefined> extends TypedContext<Params> implements CommonResponseInit {
export class Context<Params, State = undefined> implements CommonResponseInit {
state!: State;

status!: number;
headers = {} as CommonHeaders;
headers: CommonHeaders;

readonly path: string;
readonly pathStart: number;
readonly pathEnd: number;
readonly params!: Params;
readonly req: Request;

/**
* Parse the request
*/
constructor(req: Request) {
this.req = req;
this.headers = {};

const { url } = req;

const start = url.indexOf('/', 12);

const end = url.indexOf('?', start + 1);
const pathEnd = end === -1 ? url.length : end;

this.pathStart = start;
this.pathEnd = pathEnd;
this.path = url.substring(start, pathEnd);
}

/**
* Send a `BodyInit` as response
Expand Down
6 changes: 2 additions & 4 deletions tests/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Server
import { Byte, parse, cors, csrf, send } from '@bit-js/byte';
import { Byte, cors, csrf, send } from '@bit-js/byte';

// Basic responses
export const basicApis = new Byte()
Expand All @@ -8,9 +8,7 @@ export const basicApis = new Byte()

// Parse & send JSON
export const jsonApis = new Byte()
.post('/json', {
body: parse.json()
}, (ctx) => ctx.json(ctx.state.body));
.post('/json', async (ctx) => ctx.json(await ctx.req.json()));

// CORS
export const apiWithCors = new Byte()
Expand Down

0 comments on commit 9b543f0

Please sign in to comment.