add var to identify static resource requests

This commit is contained in:
HorizonCode 2023-05-12 14:10:41 +02:00
parent 06695c5443
commit e6f6b1ddc5
2 changed files with 19 additions and 2 deletions

View File

@ -23,7 +23,13 @@ httpServer.preprocessor((_req, rep) => {
httpServer.middleware(async (req, _rep, done) => { httpServer.middleware(async (req, _rep, done) => {
const processTime = await done(); const processTime = await done();
console.log(`${req.method} - ${req.remoteIpAddr} - ${req.path} - ${prettyTime(processTime)}`); if (!req.resourceRequest) {
console.log(
`${req.method} - ${req.remoteIpAddr} - ${req.path} - ${
prettyTime(processTime)
}`,
);
}
}); });
httpServer.error((req, _rep) => { httpServer.error((req, _rep) => {

13
mod.ts
View File

@ -122,6 +122,7 @@ export class HTTPServer {
conn, conn,
filepath, filepath,
url, url,
this.staticServePath ?? "",
); );
const routeReply: RouteReply = new RouteReply(); const routeReply: RouteReply = new RouteReply();
@ -347,13 +348,23 @@ export class RouteRequest {
queryParams: { [key: string]: string }; queryParams: { [key: string]: string };
pathParams: { [key: string]: string }; pathParams: { [key: string]: string };
remoteIpAddr: string; remoteIpAddr: string;
resourceRequest: boolean;
constructor(request: Request, conn: Deno.Conn, path: string, url: string) { constructor(
request: Request,
conn: Deno.Conn,
path: string,
url: string,
staticServePath: string,
) {
this.url = url; this.url = url;
this.path = decodeURIComponent(path); this.path = decodeURIComponent(path);
this.headers = request.headers; this.headers = request.headers;
this.method = request.method as HTTPMethod; this.method = request.method as HTTPMethod;
this.pathParams = {}; this.pathParams = {};
this.resourceRequest = staticServePath.length > 0
? path.startsWith(staticServePath)
: false;
this.queryParams = Object.fromEntries(new URL(url).searchParams.entries()); this.queryParams = Object.fromEntries(new URL(url).searchParams.entries());
this.remoteIpAddr = "hostname" in conn.remoteAddr this.remoteIpAddr = "hostname" in conn.remoteAddr
? conn.remoteAddr["hostname"] ? conn.remoteAddr["hostname"]