Skip to content

Commit

Permalink
fix: wrong endpoint used to connect to hpx server;
Browse files Browse the repository at this point in the history
  • Loading branch information
twiddli committed Apr 5, 2023
1 parent e0146dc commit 34596be
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 15 deletions.
7 changes: 2 additions & 5 deletions packages/client/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# HappyPanda X Web Client

##### This is a web client using NextJS to serve a HappyPanda X server.
##### This is a web client using NextJS to connect to a HappyPanda X server.

[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Pewpews/happypandax?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

Expand All @@ -17,7 +17,4 @@ Look for issues with the tag [`client rewrite`](https://github.com/happypandax/h
- Build the CSS with `yarn run:client build:css`
- Start the client with `yarn start:client`

Use `yarn run:client storybook` to start working on the UI.

## Known issues
- Needs to stay on nextjs 3.0.2 because of https://github.com/vercel/next.js/issues/43585
Use `yarn run:client storybook` to start working on the UI.
3 changes: 3 additions & 0 deletions packages/client/components/About.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ function InfoPane() {
<Grid.Column>
{data?.data?.version?.beta && <Label color="violet">{t`Beta`}</Label>}
{data?.data?.version?.alpha && <Label color="red">{t`Alpha`}</Label>}
<Label basic color="purple">
{data?.data?.version?.name}
</Label>
<Label basic>
{t`Webclient`} <Label.Detail>{packageJson?.version}</Label.Detail>
</Label>
Expand Down
25 changes: 24 additions & 1 deletion packages/client/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const http = require('http');
const dotenv = require('dotenv');
const { parseArgs } = require('util');
const nextConfigs = require('./next.config');
const packageJson = require('./package.json');
const _ = require('lodash');

const dir = __dirname;
Expand All @@ -17,7 +18,7 @@ let hostname = 'localhost';
let port = 7008;

const {
values: { host: cliHost, port: cliPort, env, help, cwd },
values: { host: cliHost, port: cliPort, env, help, cwd, version },
} = parseArgs({
options: {
host: {
Expand All @@ -38,6 +39,10 @@ const {
type: 'string',
default: '',
},
version: {
type: 'boolean',
default: false,
},
help: {
type: 'boolean',
default: false,
Expand All @@ -53,11 +58,17 @@ Options:
-p, --port Port to listen on
--cwd Working directory (defaults to where the executable is)
--env Environment variables to load
--version Displays the version
--help Displays this message
`);
process.exit(0);
}

if (version) {
console.log(packageJson.version);
process.exit(0);
}

if (env) {
console.log(`> Loading environment variables from given env`);
const envConfig = dotenv.parse(Buffer.from(env, 'utf8'));
Expand All @@ -76,6 +87,18 @@ Object.entries(process.env).forEach(([key, value]) => {
if (key === 'HPX_PORT') {
port = parseInt(value, 10);
}

if (key === 'HPX_SERVER_HOST') {
console.log(
`> Using HPX server hostname ${value} from HPX_SERVER_HOST environment variable`
);
}

if (key === 'HPX_SERVER_PORT') {
console.log(
`> Using HPX server port ${value} from HPX_SERVER_PORT environment variable`
);
}
});

if (cwd) {
Expand Down
9 changes: 5 additions & 4 deletions packages/client/server/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ export const nextAuthOptions: NextAuthOptions = {
port = HPX_SERVER_PORT;
}


if (host && port) {
await server.connect({ host, port }).catch((e: ServerError) => {
global.app.log.e(e);
Expand Down Expand Up @@ -289,10 +290,10 @@ export async function getServerSession({
req,
}: {
req?:
| (IncomingMessage & {
cookies: Partial<{ [key: string]: string }>;
})
| NextApiRequest;
| (IncomingMessage & {
cookies: Partial<{ [key: string]: string }>;
})
| NextApiRequest;
}) {
const s = await getToken({ req, secret: HPX_SECRET });
return s as { id: string };
Expand Down
13 changes: 8 additions & 5 deletions packages/client/services/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,22 +326,24 @@ export default class ServerService extends Service {
}
}

const n_endpoint = endpoint ?? this.endpoint;

global.app.log.i(
'Connecting to HPX server... at ' +
this.endpoint.host +
n_endpoint.host +
':' +
this.endpoint.port
n_endpoint.port
);

if (!client.is_connected()) {
for (const n of this.#clients) {
await n.client.connect(this.endpoint);
await n.client.connect(n_endpoint);
}

client.on('close', this._disconnect_listener);

this.emit('connect', this.endpoint);
this.endpoint = endpoint;
this.emit('connect', n_endpoint);
this.endpoint = n_endpoint;
}
} finally {
await node.release();
Expand Down Expand Up @@ -540,6 +542,7 @@ export class Server {
torrent: [number, number, number];
beta: boolean;
alpha: boolean;
name: string;
build: string;
};
user: ServerUser;
Expand Down

0 comments on commit 34596be

Please sign in to comment.