I am listening on port 3000 for http requests and 4000 for requests for socketio. The socketio request just hang though, never connecting.
Here is my fly.toml:
app = 'walk-visualization-backend'
primary_region = 'sjc'
[build]
[[services]]
internal_port = 3000
protocol = "tcp"
[[services.ports]]
handlers = ["http"]
port = "80"
[[services.ports]]
handlers = ["tls", "http"]
port = "443"
[[services]]
internal_port = 4000
protocol = "tcp"
[[services.ports]]
handlers = ["tls"]
port = "443"
Here is my socket config as well:
import { Socket } from "socket.io";
import envConfig from "./envConfig.js";
import { corsOptions } from "./corsOptions.js";
import getFrameFromIndex from "../utils/getNextFrame.js";
import { walkData } from "../data/walkData.js";
import { terrainData } from "../data/terrainData.js";
function socketConfig() {
const SOCKET_PORT = 4000;
const { Server } = require("socket.io");
const io = new Server({
cors: {
origin: corsOptions.origin
}
});
io.on("connection", (socket: Socket) => {
let intervalId: NodeJS.Timeout;
console.log("user connected")
socket.on("agent", (id) => {
console.log("agent was selected!")
clearInterval(intervalId)
socket.emit("terrain", terrainData)
let index = 0
intervalId = setInterval(() => {
socket.emit("frame", getFrameFromIndex(index))
index+=1;
if (index > walkData.length-1) {
index = 0;
}
}, 20)
})
socket.on('disconnect', () => {
clearInterval(intervalId);
console.log("a user disconnected");
})
});
io.listen(SOCKET_PORT);
}
export default socketConfig