release: 0.0.3-1

This commit is contained in:
2024-08-01 13:26:50 +08:00
parent 79b9fba1cd
commit 89c5ed561a
12 changed files with 484 additions and 31 deletions

View File

@ -29,8 +29,8 @@ export class handler<RequestCustomType, ResponseCustomType> {
case 1:
return this.responders[0](request, responseMessage);
default:
for (let responder of this.responders) {
let thisResponse = await responder(
for (const responder of this.responders) {
const thisResponse = await responder(
request,
responseMessage,
);

View File

@ -1,5 +1,5 @@
import headers from './headers';
import packageJSON from '../../package.json';
import packageJSON from '../../package.json' assert { type: 'json' };
import { platform, version } from '../lib';
export class defaultHeaders extends headers {

View File

@ -20,7 +20,9 @@ export const platform = (() => {
})();
export const version = (() => {
switch (platform) {
case 'Node.js' || 'Bun':
case 'Node.js':
return process.version;
case 'Bun':
return process.version;
case 'Deno':
return Deno.version.deno;

View File

@ -3,7 +3,7 @@ import { response } from '../../interface';
import { headers } from '../../interface/headers';
import { methodENUM } from '../../interface/method';
import statusCode from './statusCode.json';
import statusCode from './statusCode.json' assert { type: 'json' };
export class HttpConn {
private closed: boolean = false;
@ -35,8 +35,10 @@ export class HttpConn {
const url = new URL(
path,
`http://${requestHeaders.get('Host')}/` ??
`http://${this.conn.localAddress.ip}:${this.conn.localAddress.port}/`,
`http://${
requestHeaders.get('Host') ??
`${this.conn.localAddress.ip}:${this.conn.localAddress.port}`
}/`,
);
const body = lines.slice(dividingIndex + 1).join('\n');
@ -56,9 +58,9 @@ export class HttpConn {
let responseMessage: string = '';
responseMessage +=
'HTTP/1.1 ' +
response.status +
' ' +
statusCode[<'100'>response.status.toString()] ?? '';
response.status +
' ' +
(statusCode[<'100'>response.status.toString()] ?? '');
response.headers.forEach((key, value) => {
responseMessage += '\n' + key + ': ' + value;
@ -95,6 +97,7 @@ export class HttpConn {
}
[Symbol.asyncIterator]() {
// eslint-disable-next-line @typescript-eslint/no-this-alias
const httpConn = this;
return {

View File

@ -42,7 +42,7 @@ export class route {
attributes: [],
};
let attributes: matchedStatus['attributes'] = [];
const attributes: matchedStatus['attributes'] = [];
it.keys.forEach((key, index) => {
attributes.push({

View File

@ -98,7 +98,7 @@ export class router<K = any, V = any> {
let mismatchCount = 0;
for (let route of this.routes) {
for (const route of this.routes) {
const isMatched = await route.exec(request.url.pathname);
if (!isMatched.matched) {
@ -112,7 +112,7 @@ export class router<K = any, V = any> {
try {
let thisResponse: response<V> | void = responseMessage;
for (let handler of route.handlers) {
for (const handler of route.handlers) {
if (
handler.method != request.method &&
handler.method != methodENUM.ANY