【发布时间】:2016-01-20 09:12:15
【问题描述】:
以下NodeJS Hapi代码在http://localhost:3000/documentation查询时产生错误
如果我将端点的路径更改为 /models 以外的其他路径,例如 /users,则一切正常。看起来端点 /models 已保留。
知道为什么除了 /models 之外的任何其他端点都可以工作吗?我该如何解决?因为太多人使用了,所以我无法更改网址。
var Hapi = require('hapi'),
Inert = require('inert'),
Vision = require('vision'),
Joi = require('joi'),
HapiSwagger = require('hapi-swagger')
var server = new Hapi.Server();
server.connection({
host: 'localhost',
port: 3000
});
var swaggerOptions = {
apiVersion: "1.0"
};
server.register([
Inert,
Vision,
{
register: HapiSwagger,
options: swaggerOptions
}], function (err) {
server.start(function(){
// Add any server.route() config here
console.log('Server running at:', server.info.uri);
});
});
server.route(
{
method: 'GET',
path: '/models',
config: {
handler: function (request, reply) {
reply("list of models")
},
description: 'Get todo',
notes: 'Returns a todo item by the id passed in the path',
tags: ['api'],
validate: {
params: {
username: Joi.number()
.required()
.description('the id for the todo item')
}
}
}
}
)
server.start(function(){
// Add any server.route() config here
console.log('Server running at:', server.info.uri);
});
【问题讨论】: