ECONNREFUSED when calling Mockserver (express+stubby)

48 views Asked by At

I have the following server for testing purposes:

const Stubby = require('stubby').Stubby;
const express = require('express');
const proxy = require('express-http-proxy');
const path = require('path');
const yaml = require('js-yaml');
const fs = require('fs');

const app = express();
const port = 9000;

const options = (req, res, next) => {
  if (req.method === 'OPTIONS') {
    res.header('Access-Control-Allow-Origin', '*');
    res.header('Access-Control-Allow-Methods', '*');
    res.header('Access-Control-Allow-Headers', '*');
    res.status(200);
    res.send();
  } else {
    next();
  }
};

app.use('/', express.json(), options, proxy('localhost:8888'));

app.listen(port, () => {
  console.log(`Mockserver listening ${port}!`);

  const configFile = path.resolve(__dirname, 'config.yaml');

  const data = yaml.load(fs.readFileSync(configFile, 'utf8'));

  const mockService = new Stubby();
  mockService.start({ stubs: 8888, admin: 8889, data, quiet: false, watch: configFile });
});

Unfortunately it doesn't work anymore, and instead of the response I'm getting this:

Error: connect ECONNREFUSED ::1:8888
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1157:16) 

It used to work on my previous machine (MacBook with BigSur). Now I'm also on Mac but Monterey. Not sure if this might be related.

0

There are 0 answers