Skip to content

Commit 68b28dc

Browse files
committed
Added route for frontend and changed api routes to /api/*
1 parent 0a15201 commit 68b28dc

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
22

33
# dependencies
4-
/node_modules
4+
node_modules
55

66
# testing
7-
/coverage
7+
coverage
88

99
# production
10-
/build
10+
build
1111

1212
# misc
1313
.DS_Store

server/routes/containers.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const got = require("got");
33

44
const DOCKER_SOCK = process.env.REACT_APP_DOCKER_SOCK;
55

6-
const CONTAINERS = `${DOCKER_SOCK}/containers/json?all=true`;
6+
const CONTAINERS = `${DOCKER_SOCK}/containers/json?all=true&size=true`;
77
const CONTAINER_STOP = id => `${DOCKER_SOCK}/containers/${id}/stop`;
88
const CONTAINER_PRUNE = `${DOCKER_SOCK}/containers/prune`;
99
const CONTAINER = id =>
@@ -32,7 +32,6 @@ router.post("/stop", async (req, res) => {
3232

3333
try {
3434
const data = await got.post(CONTAINER_STOP(req.body.containerId));
35-
console.log(await data.statusCode);
3635
res.sendStatus(await data.statusCode);
3736
} catch (error) {
3837
res.sendStatus(error.statusCode);
@@ -46,7 +45,6 @@ router.post("/prune", async (req, res) => {
4645

4746
try {
4847
const data = await got.post(CONTAINER_PRUNE);
49-
console.log(await data.body);
5048
res.send(await data.body);
5149
} catch (error) {
5250
res.sendStatus(error.statusCode);
@@ -59,7 +57,6 @@ router.get("/:containerId", async (req, res) => {
5957

6058
try {
6159
const data = await got(CONTAINER(req.params.containerId));
62-
console.log(data.body);
6360
res.send(data.body);
6461
} catch (error) {
6562
console.error(error);
@@ -71,7 +68,6 @@ router.delete("/:containerId", async (req, res) => {
7168

7269
try {
7370
const data = await got.delete(CONTAINER_REMOVE(req.params.containerId));
74-
console.log(await data.statusCode);
7571
res.sendStatus(await data.statusCode);
7672
} catch (error) {
7773
res.sendStatus(error.statusCode);
@@ -84,7 +80,6 @@ router.post("/:containerId", async (req, res) => {
8480

8581
try {
8682
const data = await got.post(CONTAINER_START(req.params.containerId));
87-
console.log(await data.statusCode);
8883
res.sendStatus(await data.statusCode);
8984
} catch (error) {
9085
res.sendStatus(error.statusCode);
@@ -97,7 +92,6 @@ router.post("/:containerId/restart", async (req, res) => {
9792

9893
try {
9994
const data = await got.post(CONTAINER_RESTART(req.params.containerId));
100-
console.log(await data.statusCode);
10195
res.sendStatus(await data.statusCode);
10296
} catch (error) {
10397
res.sendStatus(error.statusCode);
@@ -112,7 +106,6 @@ router.post("/:containerId/rename", async (req, res) => {
112106
const data = await got.post(
113107
CONTAINER_RENAME(req.params.containerId, req.query.name)
114108
);
115-
console.log(await data.statusCode);
116109
res.sendStatus(await data.statusCode);
117110
} catch (error) {
118111
res.sendStatus(error.statusCode);
@@ -125,7 +118,6 @@ router.post("/:containerId/pause", async (req, res) => {
125118

126119
try {
127120
const data = await got.post(CONTAINER_PAUSE(req.params.containerId));
128-
console.log(await data.statusCode);
129121
res.sendStatus(await data.statusCode);
130122
} catch (error) {
131123
res.sendStatus(error.statusCode);
@@ -138,7 +130,6 @@ router.post("/:containerId/unpause", async (req, res) => {
138130

139131
try {
140132
const data = await got.post(CONTAINER_UNPAUSE(req.params.containerId));
141-
console.log(await data.statusCode);
142133
res.sendStatus(await data.statusCode);
143134
} catch (error) {
144135
res.sendStatus(error.statusCode);

server/server.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const express = require("express");
2+
const path = require("path");
23
const bodyParser = require("body-parser");
34

45
const app = express();
@@ -13,10 +14,15 @@ const images = require("./routes/images");
1314
const networks = require("./routes/networks");
1415
const volumes = require("./routes/volumes");
1516

16-
app.use("/info", info);
17-
app.use("/containers", containers);
18-
app.use("/images", images);
19-
app.use("/networks", networks);
20-
app.use("/volumes", volumes);
17+
app.use("/api/info", info);
18+
app.use("/api/containers", containers);
19+
app.use("/api/images", images);
20+
app.use("/api/networks", networks);
21+
app.use("/api/volumes", volumes);
2122

22-
app.listen(4000, () => console.log("Serving on *4000..."));
23+
app.use(express.static(path.join(__dirname, "../build")));
24+
app.get("*", (req, res) => {
25+
res.sendFile(path.join(__dirname, "../build", "index.html"));
26+
});
27+
28+
app.listen(8888, () => console.log("Serving on *8888..."));

0 commit comments

Comments
 (0)