main-site/pages/api/containers.tsx
Neshura 6af8cb3e1b
Large Code Rewrite
Added 2 API Endpoints for use with useSWR, removed the service and status fetching from getStaticProps, rewrote status fetching to use async (WIP, needs testing)
2022-12-10 03:02:03 +01:00

22 lines
619 B
TypeScript

import fsPromises from 'fs/promises'
import path from 'path'
import { Service, ServiceStatus } from '../../interfaces/LinkTypes';
export default async function ServicesAPI(req: any, res: any) {
try {
var Docker = require('dockerode');
const options = {
socketPath: '/var/run/docker.sock',
path: '/v1.41/containers/json'
};
var docker = new Docker({ socketPath: options.socketPath });
const list = await docker.listContainers({ all: true })
res.status(200).json(list);
}
catch (error) {
console.log(error);
res.status(500).json({ error: 'Error reading data' });
}
}