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