mirror of
https://github.com/186526/handlers.js
synced 2024-10-13 00:29:43 +00:00
release: 0.0.3-1
This commit is contained in:
@ -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,
|
||||
);
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -42,7 +42,7 @@ export class route {
|
||||
attributes: [],
|
||||
};
|
||||
|
||||
let attributes: matchedStatus['attributes'] = [];
|
||||
const attributes: matchedStatus['attributes'] = [];
|
||||
|
||||
it.keys.forEach((key, index) => {
|
||||
attributes.push({
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user