add var to identify static resource requests
This commit is contained in:
parent
06695c5443
commit
e6f6b1ddc5
|
@ -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
13
mod.ts
|
@ -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"]
|
||||||
|
|
Reference in New Issue
Block a user