尝试从节点服务器检索json对象时,获取“ Cannot GET /”

我正在编写RESTful API。 IT使用express.js框架在node.js上运行,mongodb使用mongoose作为对象建模工具并使用body-parser在http上运行。每次启动服务器并导航到指定的IP地址时,都会出现“ CANNOT GET /”错误。我该如何解决?一些建议将不胜感激。

我对使用其他端口号感到厌倦,但问题仍然存在。 这是我的server.js代码的副本:

class PrintWithDetail extends action
{
    use InteractsWithQueue,Queueable,SerializesModels;

    /**
     * Perform the action on the given models.
     *
     * @param  \Laravel\Nova\Fields\actionFields  $fields
     * @param  \Illuminate\Support\Collection  $models
     * @return mixed
     */
    public function handle(actionFields $fields,Collection $models)
    {
        $id = '';
        //
        foreach ($models as $model) {
            $id = $model->id;
        }
        return action::openInNewTab(route("print.work.order",[$id,'type' => 'detail']));
    }

}

todoRoute代码:

var express = require('express'),app = express(),IP = process.env.IP,port = process.env.PORT || 8080,mongoose = require('mongoose'),tasks = require('./api/models/todosModel'),bodyParser = require('body-parser');

//handiling of promise 
mongoose.Promise = global.Promise;
mongoose.connect('mongodb://localhost/Todosdb',{ useNewUrlParser: true });

app.use(bodyParser.urlencoded({extended:true})); // telling the sever instance to use body parser
app.use(bodyParser.json()); 

var Routes = require('./api/routes/todoRoutes');
//passing the server instance to the routes 
Routes(app);

app.listen(port,IP);
console.log("The TODO API server is running on IP: " + IP + " and port: " + port);
x13575102949 回答:尝试从节点服务器检索json对象时,获取“ Cannot GET /”

可能是因为您尚未为/定义任何处理程序。

尝试在浏览器中转到/tasks,然后您会得到一些响应。

本文链接:https://www.f2er.com/3138504.html

大家都在问