0

i have a node app that was previously working on version 10, now its working on version 14. I have just run npm update. I keep gettig this error when i start my server.

Unhandled error for request POST /hl7_message: Error: Cannot POST /hl7_message
    at raiseUrlNotFoundError (C:\Users\Cynthia Kamau\Documents\Node Projects\localConsumerV2\node_modules\loopback\server\middleware\url-not-found.js:21:19)     
    at Layer.handle [as handle_request] (C:\Users\Cynthia Kamau\Documents\Node Projects\localConsumerV2\node_modules\express\lib\router\layer.js:95:5)
    at trim_prefix (C:\Users\Cynthia Kamau\Documents\Node Projects\localConsumerV2\node_modules\express\lib\router\index.js:328:13)
    at C:\Users\Cynthia Kamau\Documents\Node Projects\localConsumerV2\node_modules\express\lib\router\index.js:286:9
    at Function.process_params (C:\Users\Cynthia Kamau\Documents\Node Projects\localConsumerV2\node_modules\express\lib\router\index.js:346:12)
    at next (C:\Users\Cynthia Kamau\Documents\Node Projects\localConsumerV2\node_modules\express\lib\router\index.js:280:10)
    at C:\Users\Cynthia Kamau\Documents\Node Projects\localConsumerV2\node_modules\express\lib\router\index.js:646:15
    at next (C:\Users\Cynthia Kamau\Documents\Node Projects\localConsumerV2\node_modules\express\lib\router\index.js:265:14)
    at Function.handle (C:\Users\Cynthia Kamau\Documents\Node Projects\localConsumerV2\node_modules\express\lib\router\index.js:175:3

My code looks like this :

var request = require("request");
var internetAvailable = require("internet-available");

process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;
var express = require("express");
var bodyParser = require("body-parser");

var applctn = express();

applctn.use(bodyParser.json());

applctn.use(bodyParser.urlencoded({ extended: true }));

module.exports = function (app) {
  applctn.post("/hl7_message", function (req, res, next) {
    var err = new Error("Not Found");
    err.status = 404;
    next(err);

    ("use strict");

    var hl7_message = req.body;

    internetAvailable()
      .then(function () {
        console.log("Internet available");

        //if online post incoming requests to receiver

        var options = {
          method: "POST",

          url: "https://myurl.org/hl7_message",

          headers: {
            "Content-Type": "application/json",
          },

          body: hl7_message,

          json: true,
        };

        request(options, function (error, response, body) {
          if (error) {
            console.log("here", error);
          } else if (response.statusCode == 400) {
            var s = response.body.response.data;

            console.log("im here", s);
          }

          return res.send(true);
        });
      })
      .catch(function (error) {
        console.log("No internet, saving data locally", error);
      });
  });

  applctn.get("/hl7_message", function (req, res) {
    res.send("T4A HL7 Consumer Server is running on port 1440");
  });
};

I am also using loopback middleware and it seems that it is depricated. Any advise or articles that can assist me will be highly appreciated. Thank you

CKW
  • 51
  • 5

0 Answers0