MagicMirror² v2.12.0 is available! For more information about this release, check out this topic.

expressApp.get - Error Cannot GET ...


  • Project Sponsor

    Hi,

    I intercept a webservice call via node_helper.js. Now I wanted to handle two more webservice calls. Unfortunately this doesn’t work.

    my code:

    const NodeHelper = require("node_helper")
    var async = require('async');
    var exec = require('child_process').exec;
    var express = require('express');
    var app = express();
    
    ...
    
    module.exports = NodeHelper.create({
    	
    	start: function() {
    		//console.error('Starting node helper: ' + this.name);
    		var self = this;
    		
    		// Updateinterval ändern über Aufruf http://127.0.0.1:8080/MMM-CaravanPiPosition/changeUpdateInterval
    		this.expressApp.get('/' + this.name + '/changeUpdateInterval', function (req, res) {
    			res.send('Change UpdateInterval from '+ myUpdateInterval);
    			self.changeUpdateInterval();
    		});
    		
    		// Kalibrierung anzeigen über Aufruf http://127.0.0.1:8080/MMM-CaravanPiPosition/setCalibration
    		this.expressApp.get('/' + this.name + '/setCalibration', function (req, res) {
    			res.send('set Calibration');
    			valueListNHCaravanPiPosition[0]["cal"] = 1;
    		});
    		
    		// Kalibrierung löschen über Aufruf http://127.0.0.1:8080/MMM-CaravanPiPosition/unsetCalibration
    		this.expressApp.get('/' + this.name + '/unsetCalibration', function (req, res) {
    			res.send('unset Calibration');
    			valueListNHCaravanPiPosition[0]["cal"] = 0;
    		});
    	},
    ...
    

    The call of http://127.0.0.1:8080/MMM-CaravanPiPosition/changeUpdateInterval works as desired.

    The calls of http://127.0.0.1:8080/MMM-CaravanPiPosition/setCalibration and … unsetCalibration does not work.

    Instead the error message Cannot GET /MMM-CaravanPiPosition/setCalibration is displayed.

    what am i doing wrong? can’t several different webservice calls be processed?

    Thanks for every help

    Sepp



  • @spitzlbergerj said in expressApp.get - Error Cannot GET ...:

    this.expressApp.

    where is expressApp set?

    typically it is

    const app = express()
      // setup the pattern you listen for
      app.get(url_pattern, (req,res) => {})
    

  • Project Sponsor

    Hi Sam,
    yes, I had always asked myself that, but I am still a Javascript Newby. I got the code from a forum post. After it worked with the first pattern, I thought, that’s because of my low JavaScript knowledge.

    I have now changed it with your help. And now it works.

    Thank you very much!
    Sepp




Log in to reply