小编Ell*_*s17的帖子

"[SyntaxError:意外的输入结束]"使用Express for Node.js

以下对我来说非常好:

app.get('/doi/meta/:doiName1/:doiName2', function(request, response) {

  var path = '/doi/json?doi='+request.params.doiName1+'/'+request.params.doiName2;

  // etc. 
Run Code Online (Sandbox Code Playgroud)

例如,我可以打电话:

curl -X GET http://localhost:1337/doi/meta/09.1010/9347426
Run Code Online (Sandbox Code Playgroud)

并得到我期待的回应.(注意我查询的对象的名称有斜杠.)

因为对象名称存在一些潜在的可变性,所以我需要更改服务器,以便我可以像这样构建我的查询:

curl -X GET http://localhost:1337/doi/meta?doiName=09.1010/9347426
Run Code Online (Sandbox Code Playgroud)

我尝试了很多方法,但我总是得到以下回应:

[SyntaxError: Unexpected end of input]
Run Code Online (Sandbox Code Playgroud)

这告诉我,我在错误的地方寻找问题.但是,我可以将服务器代码更改回上面,它工作正常.我的代码目前看起来像这样:

app.get('/doi/meta', function(request, response) {

  //var path = '/doi/json?doi='+request.params.doiName1+'/'+request.params.doiName2;

  var args = url.parse(request.url, true).query;
  var path = 'doi/json?doi='+args['doiName'];
  console.log('path is '+path);

  // etc. 
Run Code Online (Sandbox Code Playgroud)

永远不会到达console.log语句.导致此意外的输入结束错误的问题是什么?

node.js express

1
推荐指数
1
解决办法
2万
查看次数

标签 统计

express ×1

node.js ×1