Updates
This commit is contained in:
parent
e7414c75dd
commit
109939f6db
@ -104,7 +104,14 @@ export default function ServiceClusterServerViews({
|
|||||||
data.server?.private_ip == server.private_ip
|
data.server?.private_ip == server.private_ip
|
||||||
) {
|
) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
setTtyd(data.ttyd);
|
setTtyd(
|
||||||
|
data.ttyd
|
||||||
|
? {
|
||||||
|
...data.ttyd,
|
||||||
|
href: `${window.location.origin}${data.ttyd.url}`,
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
|
);
|
||||||
}, 2000);
|
}, 2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,7 +121,14 @@ export default function ServiceClusterServerViews({
|
|||||||
data.server?.private_ip == server.private_ip
|
data.server?.private_ip == server.private_ip
|
||||||
) {
|
) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
setTtyd(data.ttyd);
|
setTtyd(
|
||||||
|
data.ttyd
|
||||||
|
? {
|
||||||
|
...data.ttyd,
|
||||||
|
href: `${window.location.origin}${data.ttyd.url}`,
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
|
);
|
||||||
}, 2000);
|
}, 2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -22,4 +22,6 @@ export const AppData = {
|
|||||||
CookieExpirationTime: 1000 * 60 * 60 * 24 * 7, // One Week
|
CookieExpirationTime: 1000 * 60 * 60 * 24 * 7, // One Week
|
||||||
|
|
||||||
DynamicPortStart: 4700,
|
DynamicPortStart: 4700,
|
||||||
|
WebPort: 3772,
|
||||||
|
WebsocketPort: 3773,
|
||||||
} as const;
|
} as const;
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { NextApiResponse } from "next";
|
import { NextApiRequest, NextApiResponse } from "next";
|
||||||
import { ServerResponse } from "http";
|
import { IncomingMessage, ServerResponse } from "http";
|
||||||
import NSQLite from "@moduletrace/nsqlite";
|
import NSQLite from "@moduletrace/nsqlite";
|
||||||
import { NSQLITE_TURBOCI_ADMIN_USERS, NSQLiteTables } from "../../db/types";
|
import { NSQLITE_TURBOCI_ADMIN_USERS, NSQLiteTables } from "../../db/types";
|
||||||
import { User } from "../../types";
|
import { User } from "../../types";
|
||||||
@ -12,6 +12,7 @@ import dayjs from "dayjs";
|
|||||||
import grabCookieNames from "../../utils/grab-cookie-names";
|
import grabCookieNames from "../../utils/grab-cookie-names";
|
||||||
|
|
||||||
type Params = {
|
type Params = {
|
||||||
|
req: NextApiRequest | IncomingMessage;
|
||||||
res: NextApiResponse | ServerResponse;
|
res: NextApiResponse | ServerResponse;
|
||||||
user_id?: string | number;
|
user_id?: string | number;
|
||||||
password?: string;
|
password?: string;
|
||||||
@ -19,6 +20,7 @@ type Params = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default async function loginUser({
|
export default async function loginUser({
|
||||||
|
req,
|
||||||
res,
|
res,
|
||||||
user_id,
|
user_id,
|
||||||
password,
|
password,
|
||||||
@ -119,10 +121,10 @@ export default async function loginUser({
|
|||||||
name: auth_key_cookie_name,
|
name: auth_key_cookie_name,
|
||||||
value: encrypted_payload || "",
|
value: encrypted_payload || "",
|
||||||
options: {
|
options: {
|
||||||
secure: process.env.DOMAIN !== "localhost",
|
secure: req.headers.origin !== "localhost",
|
||||||
path: "/",
|
path: "/",
|
||||||
expires: expiration_date,
|
expires: expiration_date,
|
||||||
domain: process.env.DOMAIN,
|
domain: req.headers.origin,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -131,7 +133,7 @@ export default async function loginUser({
|
|||||||
options: {
|
options: {
|
||||||
path: "/",
|
path: "/",
|
||||||
expires: expiration_date,
|
expires: expiration_date,
|
||||||
domain: process.env.DOMAIN,
|
domain: req.headers.origin,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|||||||
@ -1,15 +1,17 @@
|
|||||||
import { NextApiResponse } from "next";
|
import { NextApiRequest, NextApiResponse } from "next";
|
||||||
import { ServerResponse } from "http";
|
import { IncomingMessage, ServerResponse } from "http";
|
||||||
import { deleteCookie } from "../../utils/cookies-actions";
|
import { deleteCookie } from "../../utils/cookies-actions";
|
||||||
import { APIResponseObject } from "@moduletrace/datasquirel/dist/package-shared/types";
|
import { APIResponseObject } from "@moduletrace/datasquirel/dist/package-shared/types";
|
||||||
import grabCookieNames from "../../utils/grab-cookie-names";
|
import grabCookieNames from "../../utils/grab-cookie-names";
|
||||||
|
|
||||||
type Params = {
|
type Params = {
|
||||||
res: NextApiResponse | ServerResponse;
|
res: NextApiResponse | ServerResponse;
|
||||||
|
req: NextApiRequest | IncomingMessage;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default async function logoutUser({
|
export default async function logoutUser({
|
||||||
res,
|
res,
|
||||||
|
req,
|
||||||
}: Params): Promise<APIResponseObject> {
|
}: Params): Promise<APIResponseObject> {
|
||||||
const { auth_key_cookie_name, csrf_cookie_name } = grabCookieNames();
|
const { auth_key_cookie_name, csrf_cookie_name } = grabCookieNames();
|
||||||
|
|
||||||
@ -18,14 +20,14 @@ export default async function logoutUser({
|
|||||||
name: auth_key_cookie_name,
|
name: auth_key_cookie_name,
|
||||||
options: {
|
options: {
|
||||||
path: "/",
|
path: "/",
|
||||||
domain: process.env.DOMAIN,
|
domain: req.headers.origin,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: csrf_cookie_name,
|
name: csrf_cookie_name,
|
||||||
options: {
|
options: {
|
||||||
path: "/",
|
path: "/",
|
||||||
domain: process.env.DOMAIN,
|
domain: req.headers.origin,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|||||||
@ -36,9 +36,6 @@ export default async function defaultAdminProps({
|
|||||||
const deployment = grabTurboCiConfig();
|
const deployment = grabTurboCiConfig();
|
||||||
const deployment_id = readFileSync(TURBOCI_DEPLOYMENT_ID_FILE, "utf-8");
|
const deployment_id = readFileSync(TURBOCI_DEPLOYMENT_ID_FILE, "utf-8");
|
||||||
|
|
||||||
const host = process.env.HOST || null;
|
|
||||||
const ws_url = `${host?.replace(/^http/, "ws")}/ws`;
|
|
||||||
|
|
||||||
const service = query.service_name
|
const service = query.service_name
|
||||||
? deployment.services.find(
|
? deployment.services.find(
|
||||||
(srv) => srv.service_name == query.service_name,
|
(srv) => srv.service_name == query.service_name,
|
||||||
@ -101,8 +98,6 @@ export default async function defaultAdminProps({
|
|||||||
deployment_id,
|
deployment_id,
|
||||||
service,
|
service,
|
||||||
children_services,
|
children_services,
|
||||||
ws_url,
|
|
||||||
host,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let finalProps = _.merge(props, propsFnProps, defaultPageProps);
|
let finalProps = _.merge(props, propsFnProps, defaultPageProps);
|
||||||
|
|||||||
@ -48,7 +48,7 @@ export default async function grabTtydServerInfo({
|
|||||||
|
|
||||||
const available_port = getNextAvailablePort();
|
const available_port = getNextAvailablePort();
|
||||||
|
|
||||||
let url = `${process.env.HOST}/ttyd/${available_port}`;
|
let url = `/ttyd/${available_port}`;
|
||||||
|
|
||||||
let cmd = ``;
|
let cmd = ``;
|
||||||
|
|
||||||
|
|||||||
@ -6,8 +6,6 @@ import useWebSocketEventHandler from "@/twui/components/hooks/useWebSocketEventH
|
|||||||
import { date } from "zod";
|
import { date } from "zod";
|
||||||
|
|
||||||
export default function useAppInit(pageProps: PagePropsType) {
|
export default function useAppInit(pageProps: PagePropsType) {
|
||||||
const wsURL = pageProps.ws_url || "";
|
|
||||||
|
|
||||||
const { user } = pageProps;
|
const { user } = pageProps;
|
||||||
|
|
||||||
const [toast, setToast] = React.useState<ToastType>({
|
const [toast, setToast] = React.useState<ToastType>({
|
||||||
@ -15,7 +13,7 @@ export default function useAppInit(pageProps: PagePropsType) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const { socket, sendData } = useWebSocket<WebSocketDataType>({
|
const { socket, sendData } = useWebSocket<WebSocketDataType>({
|
||||||
url: wsURL,
|
url: "/ws",
|
||||||
disableReconnect: false,
|
disableReconnect: false,
|
||||||
keepAliveDuration: 5000,
|
keepAliveDuration: 5000,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -51,7 +51,11 @@ export default async function handler(
|
|||||||
data: update,
|
data: update,
|
||||||
});
|
});
|
||||||
|
|
||||||
const updated = await loginUser({ res, user_id: user.id });
|
const updated = await loginUser({
|
||||||
|
res,
|
||||||
|
user_id: user.id,
|
||||||
|
req,
|
||||||
|
});
|
||||||
|
|
||||||
return res.json(updated);
|
return res.json(updated);
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
|||||||
@ -25,6 +25,7 @@ export default async function handler(
|
|||||||
res,
|
res,
|
||||||
email_or_username: email || username,
|
email_or_username: email || username,
|
||||||
password,
|
password,
|
||||||
|
req,
|
||||||
});
|
});
|
||||||
|
|
||||||
return res.json(logged_in_user);
|
return res.json(logged_in_user);
|
||||||
|
|||||||
@ -125,6 +125,7 @@ export default async function handler(
|
|||||||
const logged_in_user = await loginUser({
|
const logged_in_user = await loginUser({
|
||||||
res,
|
res,
|
||||||
user_id: newly_inserted_user.id,
|
user_id: newly_inserted_user.id,
|
||||||
|
req,
|
||||||
});
|
});
|
||||||
|
|
||||||
return res.json(logged_in_user);
|
return res.json(logged_in_user);
|
||||||
|
|||||||
@ -12,7 +12,10 @@ export default function LogoutPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
||||||
await logoutUser({ res: ctx.res });
|
await logoutUser({
|
||||||
|
res: ctx.res,
|
||||||
|
req: ctx.req,
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
redirect: {
|
redirect: {
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
import { createServer } from "http";
|
import { createServer } from "http";
|
||||||
import next from "next";
|
import next from "next";
|
||||||
|
import { AppData } from "../data/app-data";
|
||||||
|
|
||||||
const port = parseInt(process.env.PORT || "3000", 10);
|
const port = AppData["WebPort"] || 3000;
|
||||||
const dev = process.env.NODE_ENV !== "production";
|
const dev = process.env.NODE_ENV !== "production";
|
||||||
const app = next({ dev });
|
const app = next({ dev });
|
||||||
const handle = app.getRequestHandler();
|
const handle = app.getRequestHandler();
|
||||||
@ -12,14 +13,6 @@ app.prepare().then(() => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const full_href = `${process.env.HOST}${req.url}`;
|
|
||||||
|
|
||||||
const url = new URL(full_href);
|
|
||||||
|
|
||||||
if (url.pathname.match(/^\/api\//)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
handle(req, res);
|
handle(req, res);
|
||||||
}).listen(port);
|
}).listen(port);
|
||||||
|
|
||||||
|
|||||||
@ -196,8 +196,6 @@ export type PagePropsType = {
|
|||||||
deployment_id?: string | null;
|
deployment_id?: string | null;
|
||||||
service?: ParsedDeploymentServiceConfig | null;
|
service?: ParsedDeploymentServiceConfig | null;
|
||||||
children_services?: ParsedDeploymentServiceConfig[] | null;
|
children_services?: ParsedDeploymentServiceConfig[] | null;
|
||||||
ws_url?: string | null;
|
|
||||||
host?: string | null;
|
|
||||||
deployment_users?: NSQLITE_TURBOCI_ADMIN_USERS[] | null;
|
deployment_users?: NSQLITE_TURBOCI_ADMIN_USERS[] | null;
|
||||||
deployment_user?: NSQLITE_TURBOCI_ADMIN_USERS | null;
|
deployment_user?: NSQLITE_TURBOCI_ADMIN_USERS | null;
|
||||||
};
|
};
|
||||||
@ -288,6 +286,7 @@ export type ToastType = {
|
|||||||
|
|
||||||
export type TtydInfoObject = {
|
export type TtydInfoObject = {
|
||||||
url: string;
|
url: string;
|
||||||
|
href?: string;
|
||||||
port: number;
|
port: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import { AppData } from "../data/app-data";
|
||||||
import { WebSocketConnectedUserData, WebSocketData } from "../types";
|
import { WebSocketConnectedUserData, WebSocketData } from "../types";
|
||||||
import socketClose from "./socket-close";
|
import socketClose from "./socket-close";
|
||||||
import socketInit from "./socket-init";
|
import socketInit from "./socket-init";
|
||||||
@ -43,7 +44,7 @@ const server = Bun.serve<WebSocketData>({
|
|||||||
idleTimeout: 600,
|
idleTimeout: 600,
|
||||||
maxPayloadLength: 1024 * 1024 * 10,
|
maxPayloadLength: 1024 * 1024 * 10,
|
||||||
},
|
},
|
||||||
port: process.env.WEB_SOCKET_PORT,
|
port: AppData["WebsocketPort"],
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(`Websocket Listening on http://${server.hostname}:${server.port}`);
|
console.log(`Websocket Listening on http://${server.hostname}:${server.port}`);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user