我正在编写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);
答案 0 :(得分:1)
可能是因为您尚未为/
定义任何处理程序。
尝试在浏览器中转到/tasks
,然后您会得到一些响应。