Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I pass in a server when I pass in the app to create the server? #159

Open
jim-alexander opened this issue Jul 27, 2022 · 1 comment

Comments

@jim-alexander
Copy link

jim-alexander commented Jul 27, 2022

Big chance I'm over thinking this.. feels like a bit of chicken before the egg situation.

  const app = express()
  let server: ServerType

  if (isDev) {
    const options = {
      key: fs.readFileSync('certs/....pem'),
      cert: fs.readFileSync('certs/....pem'),
    }
    server = https.createServer(options, app)
  } else {
    server = http.createServer(app)
  }

  // Different app???
  const wsApp = expressWs(app, server)
  // app.use???

I need to pass in the server option, but to create a server I need to pass in the app.

Someone put me out of my misery 😂

@jim-alexander
Copy link
Author

It looks like what I've done is fine, but with a few changes:

const root = express()
let server: ServerType

if (isDev) {
    const options = {
      key: fs.readFileSync('certs/....pem'),
      cert: fs.readFileSync('certs/....pem'),
    }
    server = https.createServer(options, root)
} else {
    server = http.createServer(root)
}

const { app } = expressWs(root, server)

app.use...
app.ws...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant