Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Next15/React 19 Preparation/Implement T3 Stack #47

Draft
wants to merge 28 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2caa69d
npm audit fix
oxdev03 Nov 9, 2024
ace8eb0
bump packages
oxdev03 Nov 10, 2024
c389d6a
chain mongoose models to support edge runtime, switch to bcryptjs
oxdev03 Nov 12, 2024
c8d90e3
initial migration to next15, implements t3 stack, preparation for rea…
oxdev03 Nov 12, 2024
1235771
extend authorized callback
oxdev03 Nov 12, 2024
f3b2ab2
fix auth form redirect
oxdev03 Nov 12, 2024
25b22e5
initial migration of home page
oxdev03 Nov 12, 2024
302753e
run formatter
oxdev03 Nov 12, 2024
0368480
migration of all pages - wip
oxdev03 Nov 16, 2024
d360b30
wrap layout with provider
oxdev03 Nov 16, 2024
046e304
add refetch logic
oxdev03 Nov 16, 2024
c75741c
use default batch client
oxdev03 Nov 16, 2024
d97990b
shorten connection check
oxdev03 Nov 16, 2024
c27a767
update env
oxdev03 Nov 16, 2024
9d63bf2
fix edge compatibility problem
oxdev03 Nov 16, 2024
872fd7d
update dependencies
oxdev03 Nov 17, 2024
dfcf4df
deactivate loggerlink
oxdev03 Nov 17, 2024
a193a67
add serializer to all transformer, fix ui for git row
oxdev03 Nov 17, 2024
add29f2
initial migration to eslint flat config
oxdev03 Dec 18, 2024
4d28ddb
migration to eslint flat config for backend
oxdev03 Dec 18, 2024
e47c74e
initial migration to eslint flat config
oxdev03 Dec 18, 2024
60206e4
rename files
oxdev03 Dec 18, 2024
195e4db
fix more lint findings
oxdev03 Dec 18, 2024
baace97
fix linter findings
oxdev03 Dec 21, 2024
3a0a7ac
fix ts errors
oxdev03 Dec 21, 2024
9755d18
active auto format for tsx
oxdev03 Dec 21, 2024
173d542
recreate lock file
oxdev03 Dec 21, 2024
b8ce67f
include non default dirs for linting
oxdev03 Dec 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .eslintrc.js

This file was deleted.

34 changes: 34 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Next.js: debug server-side",
"cwd": "${workspaceFolder}/apps/dashboard",
"type": "node-terminal",
"request": "launch",
"command": "npm run dev"
},
{
"name": "Next.js: debug client-side",
"type": "msedge",
"request": "launch",
"url": "http://localhost:3000"
},
{
"name": "Next.js: debug full stack",
"cwd": "${workspaceFolder}/apps/dashboard",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/node_modules/.bin/next",
"runtimeArgs": ["--inspect"],
"skipFiles": ["<node_internals>/**"],
"serverReadyAction": {
"action": "debugWithEdge",
"killOnServerStop": true,
"pattern": "- Local:.+(https?://.+)",
"uriFormat": "%s",
"webRoot": "${workspaceFolder}"
}
}
]
}
18 changes: 16 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
{
"cssvar.files": ["apps/dashboard/node_modules/@mantine/core/styles.css"],
"cssvar.extensions": ["css", "scss", "tsx", "jsx"]
"[typescript]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescriptreact]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascript]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[json]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
5 changes: 0 additions & 5 deletions apps/backend/.eslintrc.js

This file was deleted.

2 changes: 1 addition & 1 deletion apps/backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The Backend is a simple Node.js application that uses the pm2 BUS API to communi

## Prerequisites

- Node.js v18
- Node.js >= v20
- MongoDB Cluster
- PM2 (installed globally)

Expand Down
4 changes: 4 additions & 0 deletions apps/backend/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { config } from "@pm2.web/eslint-config/base";

/** @type {import("eslint").Linter.Config} */
export default config;
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import EventEmitter from "node:events";

import pm2 from "pm2";

import { Packet, QueuedLog } from "../types/handler.js";
import censorMessage from "../utils/censorMessage.js";
import censorMessage from "../utils/censor-message.js";

class LogCapture {
private queuedLogs: QueuedLog[] = [];

constructor() {}

capture(): void {
pm2.launchBus((err, bus) => {
pm2.launchBus((_err, bus: EventEmitter) => {
bus.on("log:err", (packet: Packet) => {
this.queuedLogs.push({
id: packet.process.pm_id,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
// mongoose changestream
/* eslint-disable @typescript-eslint/no-misused-promises */
/* eslint-disable @typescript-eslint/no-unsafe-argument */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import { processModel } from "@pm2.web/mongoose-models";
import mongoose from "mongoose";
import pm2 from "pm2";

import processInfo from "../utils/processInfo.js";
import processInfo from "../utils/process-info.js";

const onChange = async (serverId: string) => {
const onChange = (serverId: string) => {
console.log(`[STREAM] Listening for changes on server ${serverId}`);
const filter = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { processModel, serverModel, statModel } from "@pm2.web/mongoose-models";
import { ISettingModel } from "@pm2.web/typings";

import { QueuedLog, UpdateDataResponse } from "../types/handler.js";
import processInfo from "../utils/processInfo.js";
import serverInfo from "../utils/serverInfo.js";
import processInfo from "../utils/process-info.js";
import serverInfo from "../utils/server-info.js";

export default async function updateData(
queuedLogs: QueuedLog[],
Expand All @@ -17,7 +17,7 @@ export default async function updateData(
if (currentServer) {
currentServer.name = server.name;
currentServer.heartbeat = Date.now();
currentServer.save();
await currentServer.save();
} else {
// create server
const newServer = new serverModel({
Expand Down
15 changes: 8 additions & 7 deletions apps/backend/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as dotenv from "dotenv";

import LogCapture from "./handlers/captureLogs.js";
import connectDb from "./handlers/connectDb.js";
import onChange from "./handlers/onChange.js";
import updateData from "./handlers/updateData.js";
import { getCachedSettings } from "./utils/cachedSettings.js";
import LogCapture from "./handlers/capture-logs.js";
import connectDb from "./handlers/connect-db.js";
import onChange from "./handlers/on-change.js";
import updateData from "./handlers/update-data.js";
import { getCachedSettings } from "./utils/cached-settings.js";

dotenv.config();

Expand All @@ -13,9 +13,10 @@ const logCapture = new LogCapture();

async function createInterval() {
const { polling } = await getCachedSettings();
// eslint-disable-next-line @typescript-eslint/no-misused-promises
const interval = setInterval(async () => {
await updateData(logCapture.clear(), await getCachedSettings());
const settings = await getCachedSettings();
await updateData(logCapture.clear(), settings);
// if polling changed clear interval and create new one
if (settings.polling.backend !== polling.backend) {
clearInterval(interval);
Expand All @@ -32,6 +33,6 @@ async function main() {
}

// eslint-disable-next-line unicorn/prefer-top-level-await
(async () => {
void (async () => {
await main();
})();
8 changes: 4 additions & 4 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"name": "oxdev03"
},
"private": true,
"type": "module",
"repository": {
"type": "git",
"url": "https://github.com/oxdev03/pm2.web"
Expand All @@ -32,15 +33,14 @@
"@pm2.web/typings": "*",
"bcrypt": "^5.1.1",
"bytes-iec": "^3.1.1",
"dotenv": "^16.4.5",
"pm2": "^5.4.2",
"systeminformation": "^5.23.5"
"dotenv": "^16.4.7",
"pm2": "^5.4.3",
"systeminformation": "^5.23.14"
},
"devDependencies": {
"@pm2.web/eslint-config": "*",
"@pm2.web/typescript-config": "*",
"@types/bcrypt": "^5.0.2",
"eslint": "^8.57.1",
"typescript": "^5.6.2"
}
}
2 changes: 1 addition & 1 deletion apps/backend/types/handler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IServerModel } from "@pm2.web/typings";

import { IProcessInfo } from "./info";
import type { IProcessInfo } from "./info.ts";

interface QueuedLog {
id: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { IProcessType, PROCESS_TYPES } from "@pm2.web/typings";
import bytes from "bytes-iec";
import pm2 from "pm2";

import { IProcessInfo } from "../types/info";
import { Pm2ProcessDescription } from "../types/pm2";
import type { IProcessInfo } from "../types/info.js";
import type { Pm2ProcessDescription } from "../types/pm2.js";

const getProcessInfo = async (): Promise<IProcessInfo[]> => {
const pm2List = await new Promise<Pm2ProcessDescription[]>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable unicorn/no-await-expression-member */
import si from "systeminformation";

import { IServerInfo } from "../types/info";
import type { IServerInfo } from "../types/info.js";

export default async function getServerInfo(): Promise<IServerInfo> {
const mem = await si.mem();
Expand All @@ -12,7 +12,7 @@ export default async function getServerInfo(): Promise<IServerInfo> {
cpu: (await si.currentLoad())?.currentLoad ?? 0,
memory: mem?.used ?? 0,
memoryMax: mem?.total ?? 0,
uptime: ((await si.time())?.uptime || 0) * 1000,
uptime: si.time().uptime * 1000,
},
heartbeatAt: Date.now(),
};
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/.env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
NEXTAUTH_SECRET=Generate using openssl rand -base64 32 or https://generate-secret.vercel.app/32
AUTH_SECRET=Generate using openssl rand -base64 32 or https://generate-secret.vercel.app/32
DB_URI=mongodb+srv://connecturi
NEXTAUTH_URL=http://localhost:3000
2 changes: 1 addition & 1 deletion apps/dashboard/.env.production
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
NEXTAUTH_SECRET=6ed05dbc1250ca97807099afd120dabe
AUTH_SECRET=6ed05dbc1250ca97807099afd120dabe
DB_URI=mongodb://127.0.0.1:20583/test
NEXTAUTH_URL=http://localhost:3000
2 changes: 1 addition & 1 deletion apps/dashboard/.env.test
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
NEXTAUTH_SECRET=6ed05dbc1250ca97807099afd120dabe
AUTH_SECRET=6ed05dbc1250ca97807099afd120dabe
DB_URI=mongodb://127.0.0.1:20583/test
NEXTAUTH_URL=http://localhost:3000
34 changes: 0 additions & 34 deletions apps/dashboard/.eslintrc.js

This file was deleted.

2 changes: 1 addition & 1 deletion apps/dashboard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The Dashboard is a Next.js application built on the t3 stack, utilizing trpc for

### Prerequisites

- Node v18
- Node >= v20
- MongoDB Cluster (required for Restart/Shutdown/Delete functionality) / MongoDB Atlas
- Open Port 3000 or 80,443 (if you use a reverse proxy)

Expand Down
Loading
Loading