mirror of
https://github.com/sergeyyarkov/asu_tools_service.git
synced 2026-10-11 02:19:09 +03:00
upd
This commit is contained in:
parent
db6de0b2f5
commit
8c5d52926d
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
node_modules
|
node_modules
|
||||||
uploads/*
|
uploads/*
|
||||||
.env
|
.env
|
||||||
|
.vscode
|
||||||
@ -1,3 +1,3 @@
|
|||||||
import { AsyncLocalStorage } from "node:async_hooks";
|
import { AsyncLocalStorage } from "node:async_hooks";
|
||||||
|
|
||||||
export const ctxAsyncLocalStorage = new AsyncLocalStorage();
|
export const httpStorage = new AsyncLocalStorage();
|
||||||
|
|||||||
5
index.js
5
index.js
@ -1,7 +1,7 @@
|
|||||||
import http from "node:http";
|
import http from "node:http";
|
||||||
import { routeHandler } from "./router/index.js";
|
import { routeHandler } from "./router/index.js";
|
||||||
import packageJson from "./package.json" with { type: "json" };
|
import packageJson from "./package.json" with { type: "json" };
|
||||||
import { ctxAsyncLocalStorage } from "./context.js";
|
import { httpStorage } from "./context.js";
|
||||||
// import db from "./db.js";
|
// import db from "./db.js";
|
||||||
import response from "./response.js";
|
import response from "./response.js";
|
||||||
import request from "./request.js";
|
import request from "./request.js";
|
||||||
@ -21,10 +21,11 @@ http
|
|||||||
req: Object.create(request),
|
req: Object.create(request),
|
||||||
res: Object.create(response)
|
res: Object.create(response)
|
||||||
};
|
};
|
||||||
|
|
||||||
ctx.req.req = req;
|
ctx.req.req = req;
|
||||||
ctx.res.res = res;
|
ctx.res.res = res;
|
||||||
|
|
||||||
ctxAsyncLocalStorage.run(ctx, () =>
|
httpStorage.run(ctx, () =>
|
||||||
routeHandler(url).then(() => {
|
routeHandler(url).then(() => {
|
||||||
console.log(`${new Date().toISOString()} Request: ${url.pathname}`);
|
console.log(`${new Date().toISOString()} Request: ${url.pathname}`);
|
||||||
})
|
})
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import formidable from "formidable";
|
import formidable from "formidable";
|
||||||
import { ctxAsyncLocalStorage } from "#root/context.js";
|
import { httpStorage } from "#root/context.js";
|
||||||
import { handlers as reportsHandlers } from "./reports/index.js";
|
import { handlers as reportsHandlers } from "./reports/index.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -30,7 +30,7 @@ export const ROUTE_MAP = {
|
|||||||
*/
|
*/
|
||||||
export async function routeHandler(url) {
|
export async function routeHandler(url) {
|
||||||
/** @type {HTTPContext} */
|
/** @type {HTTPContext} */
|
||||||
const ctx = ctxAsyncLocalStorage.getStore();
|
const ctx = httpStorage.getStore();
|
||||||
const { req, res } = ctx;
|
const { req, res } = ctx;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -53,7 +53,7 @@ export async function routeHandler(url) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
res.sendJson({ error: { message: "Указанный URL не имеет обработчика." } }, 404);
|
res.sendJson({ error: { message: "Route not found." } }, 404);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
res.sendJson(
|
res.sendJson(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user