我有follwing應用Express.js 404當我通過'?'給url參數
var express = require('express')
var bodyParser = require('body-parser')
var app = express();
// All cals should be application/json parser
var jsonParser = bodyParser.json();
app.use(jsonParser);
const path=require('path')
var cwd=process.cwd()
/**
* Append Below here your api endpoints
*/
var Weather=require(path.resolve(cwd,'application/controllers/weather.js'));
var w=new Weather(app);
/**
* Do not append below here your api endpoints
*/
app.listen(8000, function() {
console.log('Umbrelapp Backend app listening on port 8000!')
})
而且我有以下控制器:
/**
* @param object express The basic express onject that handles the http request
*/
function Weather(express)
{
var self=this;
var endpoint='/weather';
express.use(endpoint,function(req, res,next)
{
if(http.preprocess(req,res,next,endpoint))
{
switch (req.method) {
case 'GET':
self.get(req, res,next);
break;
default:
self.unsupportedAction(req,res,next);
}
}
});
/**
* Handler for http Get method
* @param req The http request
* @param res The http response
* @param next The next express.js http handler
*/
self.get=function(req,res,next)
{
console.log(req.params);
res.send('Hello');
};
/**
* Default handler for unwanted http methods
* @param req The http request
* @param res The http response
* @param next The next express.js http handler
*/
self.unsupportedAction=function(req,res,next)
{
res.status(405);
res.send('None shall pass');
}
}
module.exports=Weather;
但是,當我嘗試以下方法curl命令
捲曲-X GET -i http://localhost:8000/weather?hello=12;回聲
我得到如下回應
HTTP/1.1 404 Not Found
X-Powered-By: Express
X-Content-Type-Options: nosniff
Content-Type: text/html; charset=utf-8
Content-Length: 29
Date: Sat, 19 Nov 2016 18:06:41 GMT
Connection: keep-alive
Cannot GET /weather?hello=12
但是當我做了以下捲曲:
捲曲-X GET -i http://localhost:8000/weather;回聲
我獲得以下響應
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: text/html; charset=utf-8
Content-Length: 5
ETag: W/"5-ixqZU8RhEpaoJ6v4xHgE1w"
Date: Sat, 19 Nov 2016 18:08:08 GMT
Connection: keep-alive
Hello
你有什麼想法,我怎麼能在任何參數ammount的讓工作都捲曲命令給出?