mirror of
https://github.com/unraid/api.git
synced 2026-01-03 23:19:54 -06:00
feat: attempt to fix pm2
This commit is contained in:
@@ -35,6 +35,8 @@ EXPOSE 4000
|
||||
|
||||
FROM development AS builder
|
||||
|
||||
ENV NODE_ENV=production
|
||||
|
||||
COPY . .
|
||||
|
||||
CMD ["npm", "run", "build-and-pack"]
|
||||
@@ -2,8 +2,8 @@
|
||||
"apps": [
|
||||
{
|
||||
"name": "unraid-api",
|
||||
"script": "node",
|
||||
"args": "dist/main.js",
|
||||
"script": "npm",
|
||||
"args": "start",
|
||||
"log": "/var/log/unraid-api/unraid-api.log",
|
||||
"exec_mode": "fork",
|
||||
"ignore_watch": [
|
||||
|
||||
@@ -7,8 +7,9 @@
|
||||
"author": "Lime Technology, Inc. <unraid.net>",
|
||||
"license": "UNLICENSED",
|
||||
"scripts": {
|
||||
"start": "node dist/main.js",
|
||||
"build:docker": "./scripts/dc.sh run --rm builder",
|
||||
"build": "vite build",
|
||||
"build": "vite build --mode=production",
|
||||
"postbuild": "chmod +x dist/main.js && chmod +x dist/cli.js",
|
||||
"build-and-pack": "./scripts/build.mjs",
|
||||
"codegen": "MOTHERSHIP_GRAPHQL_LINK='https://staging.mothership.unraid.net/ws' graphql-codegen --config codegen.yml -r dotenv/config './.env.staging'",
|
||||
|
||||
@@ -4,27 +4,22 @@ import type { CoreResult, CoreContext } from '@app/core/types';
|
||||
import { getUnraidApiService } from '@app/core/modules/services/get-unraid-api';
|
||||
import { NODE_ENV } from '@app/environment';
|
||||
|
||||
const devNames = [
|
||||
'emhttpd',
|
||||
'rest-api',
|
||||
];
|
||||
const devNames = ['emhttpd', 'rest-api'];
|
||||
|
||||
const coreNames = [
|
||||
'unraid-api',
|
||||
];
|
||||
const coreNames = ['unraid-api'];
|
||||
|
||||
interface Service {
|
||||
online: boolean;
|
||||
uptime: string;
|
||||
version: string;
|
||||
online: boolean;
|
||||
uptime: string;
|
||||
version: string;
|
||||
}
|
||||
|
||||
interface ServiceResult extends CoreResult {
|
||||
json: Service;
|
||||
json: Service;
|
||||
}
|
||||
|
||||
interface ServiceWithName extends Service {
|
||||
name: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -33,39 +28,40 @@ interface ServiceWithName extends Service {
|
||||
* @param services
|
||||
* @param names
|
||||
*/
|
||||
const addNameToService = (services: ServiceResult[], names: string[]): ServiceWithName[] => services.map((service, index) => ({
|
||||
name: names[index],
|
||||
...service.json,
|
||||
}));
|
||||
const addNameToService = (services: ServiceResult[], names: string[]): ServiceWithName[] =>
|
||||
services.map((service, index) => ({
|
||||
name: names[index],
|
||||
...service.json,
|
||||
}));
|
||||
|
||||
interface Result extends CoreResult {
|
||||
json: ServiceWithName[];
|
||||
json: ServiceWithName[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all services.
|
||||
*/
|
||||
export const getServices = async (context: CoreContext): Promise<Result> => {
|
||||
const logErrorAndReturnEmptyArray = (error: Error) => {
|
||||
logger.error(error);
|
||||
return [];
|
||||
};
|
||||
const logErrorAndReturnEmptyArray = (error: Error) => {
|
||||
logger.error(error);
|
||||
return [];
|
||||
};
|
||||
|
||||
const devServices: ServiceResult[] = NODE_ENV === 'development' ? await Promise.all([
|
||||
getEmhttpdService(context),
|
||||
]).catch(logErrorAndReturnEmptyArray) as ServiceResult[] : [];
|
||||
const devServices: ServiceResult[] = (await Promise.all([getEmhttpdService(context)]).catch(
|
||||
logErrorAndReturnEmptyArray
|
||||
)) as ServiceResult[];
|
||||
|
||||
const coreServices: ServiceResult[] = await Promise.all([
|
||||
getUnraidApiService(context),
|
||||
]).catch(logErrorAndReturnEmptyArray) as ServiceResult[];
|
||||
const coreServices: ServiceResult[] = (await Promise.all([getUnraidApiService(context)]).catch(
|
||||
logErrorAndReturnEmptyArray
|
||||
)) as ServiceResult[];
|
||||
|
||||
const result = [
|
||||
...addNameToService(devServices, devNames),
|
||||
...addNameToService(coreServices, coreNames),
|
||||
];
|
||||
const result = [
|
||||
...addNameToService(devServices, devNames),
|
||||
...addNameToService(coreServices, coreNames),
|
||||
];
|
||||
|
||||
return {
|
||||
text: `Services: ${JSON.stringify(result, null, 2)}`,
|
||||
json: result,
|
||||
};
|
||||
return {
|
||||
text: `Services: ${JSON.stringify(result, null, 2)}`,
|
||||
json: result,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import { logger } from '@app/core/log';
|
||||
import { config } from 'dotenv';
|
||||
|
||||
export const env =
|
||||
process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test'
|
||||
? config({ debug: true, path: `./.env.${process.env.NODE_ENV}` })
|
||||
? config({ debug: true, path: `./.env.${process.env.NODE_ENV}`, encoding: 'utf-8' })
|
||||
: config({
|
||||
path: '/usr/local/unraid-api/.env',
|
||||
encoding: 'utf-8',
|
||||
});
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { remoteQueryLogger } from '@app/core/log';
|
||||
import { ENVIRONMENT } from '@app/environment';
|
||||
import { getApiApolloClient } from '@app/graphql/client/api/get-api-client';
|
||||
import {
|
||||
RemoteGraphQLEventType,
|
||||
@@ -20,17 +19,19 @@ export const executeRemoteGraphQLQuery = async (
|
||||
try {
|
||||
const parsedQuery = parseGraphQLQuery(originalBody);
|
||||
const localClient = getApiApolloClient({
|
||||
upcApiKey: apiKey
|
||||
upcApiKey: apiKey,
|
||||
});
|
||||
if (ENVIRONMENT === 'development') {
|
||||
remoteQueryLogger.debug({ query: parsedQuery.query }, '[DEVONLY] Running query');
|
||||
}
|
||||
remoteQueryLogger.trace({ query: parsedQuery.query }, '[DEVONLY] Running query');
|
||||
const localResult = await localClient.query({
|
||||
query: parsedQuery.query,
|
||||
variables: parsedQuery.variables,
|
||||
});
|
||||
if (localResult.data) {
|
||||
remoteQueryLogger.trace({ data: localResult.data }, 'Got data from remoteQuery request', data.sha256);
|
||||
remoteQueryLogger.trace(
|
||||
{ data: localResult.data },
|
||||
'Got data from remoteQuery request',
|
||||
data.sha256
|
||||
);
|
||||
|
||||
await client?.mutate({
|
||||
mutation: SEND_REMOTE_QUERY_RESPONSE,
|
||||
@@ -71,7 +72,10 @@ export const executeRemoteGraphQLQuery = async (
|
||||
} catch (error) {
|
||||
remoteQueryLogger.warn('Could not respond %o', error);
|
||||
}
|
||||
remoteQueryLogger.error('Error executing remote query %s', err instanceof Error ? err.message: 'Unknown Error');
|
||||
remoteQueryLogger.error(
|
||||
'Error executing remote query %s',
|
||||
err instanceof Error ? err.message : 'Unknown Error'
|
||||
);
|
||||
remoteQueryLogger.trace(err);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user