Skip to content

Commit 6ab9042

Browse files
committed
switch from go container to js
1 parent 3b61c41 commit 6ab9042

5 files changed

Lines changed: 55 additions & 95 deletions

File tree

fixtures/container-app/Dockerfile

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,9 @@
1-
# syntax=docker/dockerfile:1
1+
FROM node:22-alpine
22

3-
FROM golang:1.24 AS build
4-
# Set destination for COPY
5-
WORKDIR /app
3+
WORKDIR /usr/src/app
4+
RUN echo '{"name": "simple-node-app", "version": "1.0.0", "dependencies": {"ws": "^8.0.0"}}' > package.json
5+
RUN npm install
66

7-
# Download Go modules
8-
COPY container/go.mod container/go.sum ./
9-
RUN go mod download
10-
11-
# Copy container src
12-
COPY container/*.go ./
13-
# Build
14-
RUN CGO_ENABLED=0 GOOS=linux go build -o /server
15-
16-
FROM debian:latest
17-
COPY --from=build /server /server
7+
COPY ./container/simple-node-app.js app.js
188
EXPOSE 8080
19-
# Run
20-
CMD ["/server"]
9+
CMD [ "node", "app.js" ]

fixtures/container-app/container/go.mod

Lines changed: 0 additions & 8 deletions
This file was deleted.

fixtures/container-app/container/go.sum

Lines changed: 0 additions & 4 deletions
This file was deleted.

fixtures/container-app/container/main.go

Lines changed: 0 additions & 66 deletions
This file was deleted.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
const { createServer } = require("http");
2+
3+
const webSocketEnabled = process.env.WS_ENABLED === "true";
4+
5+
// Create HTTP server
6+
const server = createServer(function (req, res) {
7+
if (req.url === "/ws") {
8+
// WebSocket upgrade will be handled by the WebSocket server
9+
return;
10+
}
11+
12+
res.writeHead(200, { "Content-Type": "text/plain" });
13+
res.write("Hello World!");
14+
res.end();
15+
});
16+
17+
// Check if WebSocket functionality is enabled
18+
if (webSocketEnabled) {
19+
const WebSocket = require("ws");
20+
21+
// Create WebSocket server
22+
const wss = new WebSocket.Server({
23+
server: server,
24+
path: "/ws",
25+
});
26+
27+
wss.on("connection", function connection(ws) {
28+
console.log("WebSocket connection established");
29+
30+
ws.on("message", function message(data) {
31+
console.log("Received:", data.toString());
32+
// Echo the message back with prefix
33+
ws.send("Echo: " + data.toString());
34+
});
35+
36+
ws.on("close", function close() {
37+
console.log("WebSocket connection closed");
38+
});
39+
40+
ws.on("error", console.error);
41+
});
42+
}
43+
44+
server.listen(8080, function () {
45+
console.log("Server listening on port 8080");
46+
if (webSocketEnabled) {
47+
console.log("WebSocket support enabled");
48+
}
49+
});

0 commit comments

Comments
 (0)