checking on url status before fulfilling a promise

I have an atypical use case for the cypress test runner, where I need to start the server from within the cypress.
I’m doing that by defining the before:spechook in cypress plugins/index.jslike so:

module.exports = (on, config) => {
    on('before:spec', async(spec) => {
        // the promise will be awaited before the runner continues with the spec
        return new Promise((resolve, reject) => {
            startServer();
            // keep checking that the url accessible, when it is: resolve(null)
 
            while (true) {
                getStatus(function(statusCode) {
                    if (statusCode === 200)
                        break
                })
            };
            resolve(null)

I’m struggling to implement this while loop that is supposed to keep checking if the url is accessible before fulfilling the before:spec promise.
I have the following function for checking the url:

function getStatus (callback) {
  const options = {
    hostname: 'localhost',
    port: 8080,
    path: '/',
    method: 'GET'
  }
  const req = http.request(options, res => {
  console.log(`statusCode: ${res.statusCode}`)
  callback(res.statusCode}
  })
  req.on('error', error => {
    console.error("ERROR",error)
  })
  req.end()

};

Any help implementing that loop or other suggestions how to achieve the task of checking the url before fulfilling the before:specpromise appreciated.