clean up imports in index.ts and router.ts, improve types in router.ts and types.d.ts
This commit is contained in:
parent
57f8c5d18c
commit
edd50ef9b1
@ -2,10 +2,10 @@ import http, { IncomingMessage, ServerResponse } from "node:http";
|
|||||||
import { URL } from "node:url";
|
import { URL } from "node:url";
|
||||||
import querystring from "node:querystring";
|
import querystring from "node:querystring";
|
||||||
|
|
||||||
import Router from "./router.js";
|
import Router from "./router";
|
||||||
import Tpl from "./template.js";
|
import Tpl from "./template";
|
||||||
|
|
||||||
import { Request, Response, Middleware } from "./types.js";
|
import { Request, Response, Middleware } from "./types";
|
||||||
|
|
||||||
export { Router, Tpl };
|
export { Router, Tpl };
|
||||||
|
|
||||||
@ -114,7 +114,7 @@ export default class Flummpress {
|
|||||||
};
|
};
|
||||||
req.cookies = {};
|
req.cookies = {};
|
||||||
if(req.headers.cookie) {
|
if(req.headers.cookie) {
|
||||||
req.headers.cookie.split("; ").forEach((cookie) => {
|
req.headers.cookie.split("; ").forEach(cookie => {
|
||||||
const [key, value] = cookie.split("=");
|
const [key, value] = cookie.split("=");
|
||||||
req.cookies[key] = decodeURIComponent(value);
|
req.cookies[key] = decodeURIComponent(value);
|
||||||
});
|
});
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import fs from "node:fs";
|
import fs from "node:fs";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import Tpl from "./template.js";
|
import Tpl from "./template";
|
||||||
|
|
||||||
import { Middleware, RouteCallback } from "./types.js";
|
import { Request, Middleware, RouteCallback } from "./types";
|
||||||
|
|
||||||
export default class Router {
|
export default class Router {
|
||||||
private routes: Map<RegExp | string, { [key: string]: RouteCallback | RouteCallback[] }>;
|
private routes: Map<RegExp | string, { [key: string]: RouteCallback | RouteCallback[] }>;
|
||||||
@ -232,9 +232,9 @@ export default class Router {
|
|||||||
if(!this.mimes.size)
|
if(!this.mimes.size)
|
||||||
this.readMimes();
|
this.readMimes();
|
||||||
|
|
||||||
this.get(route, (req: any, res: any) => {
|
this.get(route, (req: Request, res: any) => {
|
||||||
try {
|
try {
|
||||||
const filename = req.url.pathname.replace(route, "") || "index.html";
|
const filename = req.parsedUrl.pathname.replace(route, "") || "index.html";
|
||||||
const mime = this.mimes.get(filename.split(".").pop() || "");
|
const mime = this.mimes.get(filename.split(".").pop() || "");
|
||||||
const file = path.join(dir, filename);
|
const file = path.join(dir, filename);
|
||||||
const stat = fs.statSync(file);
|
const stat = fs.statSync(file);
|
||||||
|
2
src/types.d.ts
vendored
2
src/types.d.ts
vendored
@ -7,7 +7,7 @@ export interface Request extends IncomingMessage {
|
|||||||
searchParams: URLSearchParams;
|
searchParams: URLSearchParams;
|
||||||
qs: Record<string, string>;
|
qs: Record<string, string>;
|
||||||
};
|
};
|
||||||
cookies: Record<string, string>;
|
cookies?: Record<string, string>;
|
||||||
params?: Record<string, string>;
|
params?: Record<string, string>;
|
||||||
post?: Record<string, string>;
|
post?: Record<string, string>;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user