0

I'm having issues with getting a flask server to receive a GET request from a js file ran like this in PowerShell.

node myfile.js

Here is the error

Error: TypeError: fetch failed
    at Object.fetch (node:internal/deps/undici/undici:11457:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  cause: Error: connect ECONNREFUSED ::1:44444
      at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16) {
    errno: -4078,
    code: 'ECONNREFUSED',
    syscall: 'connect',
    address: '::1',
    port: 44444
  }
}

Here is the python code

from flask import Flask, jsonify
from flask_cors import CORS

app = Flask(__name__)
CORS(app)

@app.route('/startup', methods=['GET'])
def startup():
    response = {'message': 'Server has started!'}
    return jsonify(response), 200

if __name__ == '__main__':
    app.run(host='localhost', port=44444)

Here is the javascript code

fetch('http://localhost:44444/startup', {
    method: 'GET',
    })
    .then(response => response.json())
    .then(data => console.log(data))
    .catch((error) => {
        console.error('Error:', error);
    });

The weirdest thing is I get this when I check to see if that endpoint is functioning correctly using curl

here is what i did

curl http://localhost:44444/startup


StatusCode        : 200
StatusDescription : OK
Content           : {"message":"Server has started!"}

RawContent        : HTTP/1.1 200 OK
                    Access-Control-Allow-Origin: *
                    Connection: close
                    Content-Length: 34
                    Content-Type: application/json
                    Date: Tue, 11 Jul 2023 22:31:14 GMT
                    Server: Werkzeug/2.2.3 Python/3.11.2

                    {"m...
Forms             : {}
Headers           : {[Access-Control-Allow-Origin, *], [Connection, close], [Content-Length, 34], [Content-Type,
                    application/json]...}
Images            : {}
InputFields       : {}
Links             : {}
ParsedHtml        : mshtml.HTMLDocumentClass
RawContentLength  : 34

0 Answers0