Progress on #18
This commit is contained in:
parent
a9130c1af8
commit
6a2dc0d4d8
7 changed files with 167 additions and 109 deletions
|
@ -1,6 +1,6 @@
|
|||
import fsPromises from 'fs/promises'
|
||||
import path from 'path'
|
||||
import { Service, ServiceStatus } from '../../interfaces/Services';
|
||||
import { Service, Status } from '../../interfaces/CardTypes';
|
||||
|
||||
export default async function ServicesAPI(req: any, res: any) {
|
||||
try {
|
||||
|
@ -8,7 +8,7 @@ export default async function ServicesAPI(req: any, res: any) {
|
|||
const data = await fsPromises.readFile(filePath)
|
||||
.then((file) => JSON.parse(file.toString()));
|
||||
data.services.forEach((service: Service) => {
|
||||
service.status = ServiceStatus.loading;
|
||||
service.status = Status.loading;
|
||||
});
|
||||
|
||||
res.status(200).json(data.services);
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import Head from 'next/head'
|
||||
import fsPromises from 'fs/promises'
|
||||
import path from 'path'
|
||||
import type { CustomLink, EntryList } from '../interfaces/LinkTypes'
|
||||
import { PageContentBox, PageCard, PageDescription, PageTitle, CardContentGame } from '../components/styles/content'
|
||||
import { EntryList, Game } from '../interfaces/CardTypes';
|
||||
import { PageContentBox, PageDescription, PageTitle, CardContentGame } from '../components/styles/content'
|
||||
import Link from 'next/link'
|
||||
|
||||
function Servers(props: EntryList) {
|
||||
|
@ -24,25 +24,9 @@ function Servers(props: EntryList) {
|
|||
</PageDescription>
|
||||
|
||||
<PageContentBox>
|
||||
{Object.values(serverList).map((item: CustomLink) => {
|
||||
if (item.href != null) {
|
||||
return (
|
||||
<PageCard key={item.name}>
|
||||
<Link href={item.href}>
|
||||
<CardContentGame content={item} />
|
||||
</Link>
|
||||
</PageCard>
|
||||
)
|
||||
}
|
||||
else {
|
||||
return (
|
||||
<PageCard key={item.name}>
|
||||
<CardContentGame content={item} />
|
||||
</PageCard>
|
||||
)
|
||||
}
|
||||
}
|
||||
)}
|
||||
{Object.values(serverList).map((item: Game) => (
|
||||
<CardContentGame key={item.name} content={item} />
|
||||
))}
|
||||
</PageContentBox>
|
||||
</>
|
||||
)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import Head from 'next/head'
|
||||
import Link from 'next/link'
|
||||
import { Service, ServiceStatus, ServiceType, ServiceLocation } from '../interfaces/Services';
|
||||
import { Service, Status, ServiceType, ServiceLocation } from '../interfaces/CardTypes';
|
||||
import Dockerode from 'dockerode';
|
||||
import { ReactElement } from 'react'
|
||||
import useSWR from 'swr';
|
||||
|
@ -19,11 +19,7 @@ function Services() {
|
|||
content =
|
||||
<PageContentBox>
|
||||
{initialData?.map((item: Service) => (
|
||||
<PageCard key={item.name}>
|
||||
<Link key={item.name} href={item.href}>
|
||||
<CardContentService content={item} />
|
||||
</Link>
|
||||
</PageCard>
|
||||
<CardContentService key={item.name} content={item} />
|
||||
))}
|
||||
</PageContentBox>
|
||||
|
||||
|
@ -32,11 +28,7 @@ function Services() {
|
|||
content =
|
||||
<PageContentBox>
|
||||
{fullData.map((item: Service) => (
|
||||
<PageCard key={item.name}>
|
||||
<Link key={item.name} href={item.href}>
|
||||
<CardContentService content={item} />
|
||||
</Link>
|
||||
</PageCard>
|
||||
<CardContentService key={item.name} content={item} />
|
||||
))}
|
||||
</PageContentBox>
|
||||
}
|
||||
|
@ -81,19 +73,19 @@ async function getStatus(entry: Service, containers: Dockerode.ContainerInfo[])
|
|||
case 200:
|
||||
case 301:
|
||||
case 302:
|
||||
entry.status = ServiceStatus.online;
|
||||
entry.status = Status.online;
|
||||
break;
|
||||
default:
|
||||
entry.status = ServiceStatus.offline;
|
||||
entry.status = Status.offline;
|
||||
}
|
||||
}
|
||||
else {
|
||||
entry.status = ServiceStatus.offline;
|
||||
entry.status = Status.offline;
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error pinging Website: ", error);
|
||||
entry.status = ServiceStatus.error;
|
||||
entry.status = Status.error;
|
||||
})
|
||||
}
|
||||
// Type Docker
|
||||
|
@ -107,11 +99,11 @@ async function getStatus(entry: Service, containers: Dockerode.ContainerInfo[])
|
|||
// so far only "running" is properly implemented, mroe cases to follow as needed
|
||||
switch (container.State) {
|
||||
case "running":
|
||||
entry.status = ServiceStatus.online;
|
||||
entry.status = Status.online;
|
||||
break;
|
||||
default:
|
||||
console.log("Container Status " + container.State + " has no case implemented");
|
||||
entry.status = ServiceStatus.offline;
|
||||
entry.status = Status.offline;
|
||||
}
|
||||
found = true;
|
||||
// cancel the for
|
||||
|
@ -119,7 +111,7 @@ async function getStatus(entry: Service, containers: Dockerode.ContainerInfo[])
|
|||
}
|
||||
// If container name is not missing the container is set to offline
|
||||
else {
|
||||
entry.status = ServiceStatus.offline;
|
||||
entry.status = Status.offline;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
|
@ -129,13 +121,13 @@ async function getStatus(entry: Service, containers: Dockerode.ContainerInfo[])
|
|||
// if name is null do not enter for loop
|
||||
else {
|
||||
console.error("Container Name not specified");
|
||||
entry.status = ServiceStatus.error;
|
||||
entry.status = Status.error;
|
||||
}
|
||||
}
|
||||
// If no Type matches
|
||||
else {
|
||||
console.warn("Service Type for Service " + entry.name + " not specified or invalid");
|
||||
entry.status = ServiceStatus.error;
|
||||
entry.status = Status.error;
|
||||
}
|
||||
}
|
||||
// Location Other
|
||||
|
@ -149,25 +141,25 @@ async function getStatus(entry: Service, containers: Dockerode.ContainerInfo[])
|
|||
case 200:
|
||||
case 301:
|
||||
case 302:
|
||||
entry.status = ServiceStatus.online;
|
||||
entry.status = Status.online;
|
||||
break;
|
||||
default:
|
||||
entry.status = ServiceStatus.offline;
|
||||
entry.status = Status.offline;
|
||||
}
|
||||
}
|
||||
else {
|
||||
entry.status = ServiceStatus.offline;
|
||||
entry.status = Status.offline;
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error pinging Website: ", error);
|
||||
entry.status = ServiceStatus.error;
|
||||
entry.status = Status.error;
|
||||
})
|
||||
}
|
||||
// If no Location matches
|
||||
else {
|
||||
console.warn("Service Location for Service " + entry.name + " not specified");
|
||||
entry.status = ServiceStatus.error;
|
||||
entry.status = Status.error;
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue