Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"mime": "^4.1.0",
"nanoid": "^5.1.7",
"next": "16.2.6",
"ip-address": "^10.1.0",
Comment thread
kouellette marked this conversation as resolved.
Outdated
"node-cache": "5.1.2",
"node-gyp": "12.2.0",
"node-schedule": "2.1.1",
Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,19 +267,27 @@ app

const port = Number(process.env.PORT) || 5055;
const host = process.env.HOST;
let httpServer;
if (host) {
server.listen(port, host, () => {
httpServer = server.listen(port, host, () => {
logger.info(`Server ready on ${host} port ${port}`, {
label: 'Server',
});
});
} else {
server.listen(port, () => {
httpServer = server.listen(port, () => {
logger.info(`Server ready on port ${port}`, {
label: 'Server',
});
});
}
httpServer.on('error', (err) => {
logger.error('Failed to start server', {
label: 'Server',
message: err.message,
});
process.exit(1);
});
Comment thread
kouellette marked this conversation as resolved.
})
.catch((err) => {
logger.error(err.stack);
Expand Down
9 changes: 3 additions & 6 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { User } from '@app/hooks/useUser';
import { Permission, useUser } from '@app/hooks/useUser';
import '@app/styles/globals.css';
import { polyfillIntl } from '@app/utils/polyfillIntl';
import { getHostAndPort } from '@app/utils/urlHelper';
import '@fontsource-variable/inter';
import { MediaServerType } from '@server/constants/server';
import type { PublicSettingsResponse } from '@server/interfaces/api/settingsInterfaces';
Expand Down Expand Up @@ -266,9 +267,7 @@ CoreApp.getInitialProps = async (initialProps) => {
if (ctx.res) {
// Check if app is initialized and redirect if necessary
const response = await axios.get<PublicSettingsResponse>(
`http://${process.env.HOST || 'localhost'}:${
process.env.PORT || 5055
}/api/v1/settings/public`
`http://${getHostAndPort()}/api/v1/settings/public`
);

currentSettings = response.data;
Expand All @@ -286,9 +285,7 @@ CoreApp.getInitialProps = async (initialProps) => {
try {
// Attempt to get the user by running a request to the local api
const response = await axios.get<User>(
`http://${process.env.HOST || 'localhost'}:${
process.env.PORT || 5055
}/api/v1/auth/me`,
`http://${getHostAndPort()}/api/v1/auth/me`,
{
headers:
ctx.req && ctx.req.headers.cookie
Expand Down
5 changes: 2 additions & 3 deletions src/pages/collection/[collectionId]/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import CollectionDetails from '@app/components/CollectionDetails';
import { getHostAndPort } from '@app/utils/urlHelper';
import type { Collection } from '@server/models/Collection';
import axios from 'axios';
import type { GetServerSideProps, NextPage } from 'next';
Expand All @@ -15,9 +16,7 @@ export const getServerSideProps: GetServerSideProps<
CollectionPageProps
> = async (ctx) => {
const response = await axios.get<Collection>(
`http://${process.env.HOST || 'localhost'}:${
process.env.PORT || 5055
}/api/v1/collection/${ctx.query.collectionId}`,
`http://${getHostAndPort()}/api/v1/collection/${ctx.query.collectionId}`,
{
headers: ctx.req?.headers?.cookie
? { cookie: ctx.req.headers.cookie }
Expand Down
5 changes: 2 additions & 3 deletions src/pages/movie/[movieId]/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import MovieDetails from '@app/components/MovieDetails';
import { getHostAndPort } from '@app/utils/urlHelper';
import type { MovieDetails as MovieDetailsType } from '@server/models/Movie';
import axios from 'axios';
import type { GetServerSideProps, NextPage } from 'next';
Expand All @@ -15,9 +16,7 @@ export const getServerSideProps: GetServerSideProps<MoviePageProps> = async (
ctx
) => {
const response = await axios.get<MovieDetailsType>(
`http://${process.env.HOST || 'localhost'}:${
process.env.PORT || 5055
}/api/v1/movie/${ctx.query.movieId}`,
`http://${getHostAndPort()}/api/v1/movie/${ctx.query.movieId}`,
{
headers: ctx.req?.headers?.cookie
? { cookie: ctx.req.headers.cookie }
Expand Down
5 changes: 2 additions & 3 deletions src/pages/tv/[tvId]/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import TvDetails from '@app/components/TvDetails';
import { getHostAndPort } from '@app/utils/urlHelper';
import type { TvDetails as TvDetailsType } from '@server/models/Tv';
import axios from 'axios';
import type { GetServerSideProps, NextPage } from 'next';
Expand All @@ -15,9 +16,7 @@ export const getServerSideProps: GetServerSideProps<TvPageProps> = async (
ctx
) => {
const response = await axios.get<TvDetailsType>(
`http://${process.env.HOST || 'localhost'}:${
process.env.PORT || 5055
}/api/v1/tv/${ctx.query.tvId}`,
`http://${getHostAndPort()}/api/v1/tv/${ctx.query.tvId}`,
{
headers: ctx.req?.headers?.cookie
? { cookie: ctx.req.headers.cookie }
Expand Down
12 changes: 12 additions & 0 deletions src/utils/urlHelper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Address6 } from 'ip-address';

export function getHostAndPort(): string {
let host = process.env.HOST || 'localhost';
if (Address6.isValid(host)) {
// If host is an IPv6 literal it needs to be placed in square brackets
host = `[${host}]`;
}

const port = Number(process.env.PORT) || 5055;
return `${host}:${port}`;
}
Loading