Skip to content
Snippets Groups Projects
Forked from sweng-group-15 / drawing-app
318 commits behind the upstream repository.
server.js 1.19 KiB
import dotenv from "dotenv"
import express from "express"
import http from "http"
import process from "process"
import signalbuddy from "signalbuddy"

dotenv.config()

const host = "0.0.0.0"
const port = parseInt(process.env.PORT) || 3000

const app = express()
const server = http.createServer(app)

const config = {
  rooms: {
    maxClients: 0, // no limit
  },
  ice: {
    host: process.env.ICE_HOST || "localhost",
    port: parseInt(process.env.ICE_PORT) || 3478,
    stun: {
      username: process.env.ICE_STUN_USERNAME || "user",
      password: process.env.ICE_STUN_PASSWORD || "password",
    },
    turn: {
      secret: process.env.ICE_TURN_SECRET || "secret",
      timeout: parseInt(process.env.ICE_TURN_TIMEOUT) || 86400,
    },
  },
}

signalbuddy(server, config)

app.use((request, response, next) => {
  response.on("finish", () => {
    console.log(
      "[%s] [%s]: %s %s",
      `${new Date()}`.split(" ", 5).join(" "),
      response.statusCode,
      request.method.padStart(7),
      request.originalUrl,
    )
  })
  next()
})

app.use("/", express.static("public"))

server.listen(port, host, () => {
  console.log(`Listening on http://${host}:${port}`)
  process.on("SIGINT", process.exit)
})