Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import "module-alias/register";
- import { createServer } from "node:http";
- import { parse } from "url";
- import next from "next";
- import { isProd } from "@/lib/environments";
- import { envSettingKeys } from "@root/infra/env-settings";
- import { getNumberEnvSetting, getStringEnvSetting } from "@root/infra/env-functions";
- import * as dotenv from "dotenv";
- import { initSocket } from "@server/fd/fd-toolbox-web/services/web-socket-server";
- import { initializeInternalMetaCache } from "./server/meta/fd-meta/resources/init-internal-resource-metas-from-json";
- import chokidar from "chokidar";
- dotenv.config();
- const dev = process.env.NODE_ENV !== "production";
- const protocol = getStringEnvSetting(envSettingKeys.protocol) || "http";
- const hostname = isProd() ? getStringEnvSetting(envSettingKeys.hostname) || "localhost" : "localhost";
- const port = getNumberEnvSetting(envSettingKeys.port) ?? 3000;
- const url = `${protocol}://${hostname}:${port}`;
- const pathToWatch = "/Users/air/develop/saas-kit/";
- const watcher = chokidar.watch(pathToWatch, {
- persistent: true,
- ignoreInitial: true,
- ignored: /node_modules/,
- depth: 99,
- });
- const app = next({ dev, hostname, port });
- const handler = app.getRequestHandler();
- async function run() {
- watcher
- .on("add", (path: string) => console.log(`Файл добавлен: ${path}`))
- .on("change", (path: string) => console.log(`Файл изменен: ${path}`))
- .on("unlink", (path: string) => console.log(`Файл удален: ${path}`))
- .on("addDir", (path: string) => console.log(`Папка добавлена: ${path}`))
- .on("unlinkDir", (path: string) => console.log(`Папка удалена: ${path}`))
- .on("error", (error: any) => console.error(`Ошибка: ${error}`));
- await app.prepare();
- const httpServer = createServer((req, res) => {
- const parsedUrl = parse(req.url!, true);
- handler(req, res, parsedUrl);
- });
- initSocket(httpServer);
- httpServer
- .once("error", (err) => {
- console.error(err);
- process.exit(1);
- })
- .listen(port, () => {
- console.log(`> Ready on ${url}`);
- });
- await initializeInternalMetaCache();
- }
- run();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement