获取错误响应,状态为:URL找不到404 [英] Getting error Response with status: 404 Not Found for URL

查看:120
本文介绍了获取错误响应,状态为:URL找不到404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在运行我试图与Neo4j应用程序集成的angular和nodejs应用程序时遇到问题.问题是我得到的错误-

I am facing an issue while running the angular and nodejs app which I am trying to integrate with Neo4j app. The issues are the errors that I get-

POST http://localhost:7474/viewNodesStart 404 (Not Found)

EXCEPTION: Response with status: 404 Not Found for URL: 
http://localhost:7474/viewNodesStart

尽管该主题在StackOverflow中是重复性的,但我仍在发布它,因为以下链接建议不适合我的问题.

Though this topic is repetitive in StackOverflow , I am still posting it because the following links suggestions didn't suit my issue.

找不到URL的Angular2 404: http://localhost/WebApi2/api/hero

例外:状态为404的响应URL/Angular2

> https://github.com/johnpapa/angular-tour -of-heroes/issues/94

请检查我的代码

app.component.ts

import { Component, OnInit } from '@angular/core';
import { Injectable } from '@angular/core';

import { ToasterService } from '../toaster.service';

import { FormGroup, FormControl, FormBuilder, Validators } from '@angular/forms';
import { Http, Response, Headers } from '@angular/http';
import { config } from '../config';
import { Subject } from 'rxjs';
import 'rxjs/add/operator/map';
import { map } from 'rxjs/operators';
import 'rxjs/Rx';
import { Observable } from 'rxjs';

// Statics
import 'rxjs/add/observable/throw';


@Component({
  selector: 'app-neo4j-primary',
  templateUrl: './neo4j-primary.component.html',
  styleUrls: ['./neo4j-primary.component.css']
})

export class Neo4jPrimaryComponent implements OnInit {

  constructor(private http: Http,  private notify: ToasterService) { }

  ngOnInit() {
    this.viewNodesStart();
  }


  emptyObj;
  info;

  // -------------------------------  Nodes Entire Data --------------

   viewNodesStart() {

    console.log("INSIDE viewNodesStart()")

    // Nodes Value

    console.log("inside Nodes Value");
    var data = localStorage.getItem('token');

    console.log("data is=>",data);

    var url = config.url;
    var port = config.port;

    this.http.post("http://"+url+":"+port+"/viewNodesStart",this.emptyObj)
      .map(Response => Response.json())
      .subscribe((res: Response) => {

        console.log("XXXXXXXXXXXX Response on /viewNodesStart", res);

        this.info = res;

        console.log('success', this.info.statusCode);
        if (this.info.statusCode == 200) {
          this.notify.Success("Data added successfully");

        } else {
          this.notify.Error("Data is not inserted")
        }
      });

  }

}

server.js

var express = require('express');
var cors = require('cors');
var bodyParser = require('body-parser');
const neo4j = require('neo4j-driver').v1;

var app = express();
var restify = require('restify');
var expressJwt = require('express-jwt');
var session = require('express-session');
var config = require('./config.json')

app.use(restify.plugins.bodyParser());

app.use(bodyParser.urlencoded({
  extended: false
}));

app.use(bodyParser.json());

app.use(bodyParser.json({
  type: 'application/vnd.api+json'
}))

app.use(cors());

app.use(session({
  secret: config.secret,
  resave: false,
  saveUninitialized: true
}));

//*****TM Server ******/

app.use('/viewNodesStart', require('./neo4jserver/tmserver'));

app.get('/', function(req, res) {
  res.send('Welcome');
  console.log("welcome in console");

});

// start server
var server = app.listen(7473, function() {
  console.log('Server listening at http://' + server.address().address + ':' + server.address().port);
});

nodeserver.js

// Require Neo4j
var neo4j = require('neo4j-driver').v1;
var path = require('path');
var logger = require('morgan');
var bodyParser = require('body-parser');
var express = require('express');

var router = express.Router();
var app = express();

// Create Driver
const driver = new neo4j.driver("bolt://localhost:11001",neo4j.auth.basic("neo4j", "abc"));

// Run Cypher query
const cypher = 'MATCH (n) RETURN count(n) as count';

//View Engine

app.set('views', path.join(__dirname, 'views'));

app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
  extended: false
}));
app.use(express.static(path.join(__dirname, 'public')));

var session = driver.session();

app.post('/', function(req, res) {
  console.log("INSIDE NODE JS CONTROLLER OF viewNodesStart");
  console.log("BODY IS ", req.body);

  var log = JSON.parse(req.body);

  console.log(log);
  session.run('MATCH (n) RETURN n LIMIT 25').then(function(result) {
    result.records.forEach(function(record) {
      console.log("record", record);
      console.log("result = ", result)

      console.log("record._fields[0].properties", record._fields[0].properties);
      res.status(200).send({
        statusCode: '200',
        result: result
      });
    });
  }).catch(function(err) {
    console.log(err);
  }).then(res=>{
    console.log("res.records.length", res.records.length);
  }
  )
  res.send('It Works');
  res.send(result);

});

var allowCrossDomain = function(req, res, next) {
  res.header('Access-Control-Allow-Origin', '*');
  res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
  res.header('Access-Control-Allow-Headers', 'Content-Type');
  if (req.method === "OPTIONS")
    res.send(200);
  else
    next();
}

console.log('Server started on port 11005');

module.exports = router;
module.exports = app;

推荐答案

我猜问题出在传递给http请求的url上.您正在传递环行路线的路径,并想调用节点api. 将那里的网址更改为nodeapi网址.然后它将起作用.

I guess the problem is with the url you are passing to the http request. You are passing the path of the anuglar route and want to call the node api. Change the url there to the nodeapi url. Then it will work.

这篇关于获取错误响应,状态为:URL找不到404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆