{"action":"created","issue":{"url":"https://api.github.com/repos/thinkjs/thinkjs/issues/1251","repository_url":"https://api.github.com/repos/thinkjs/thinkjs","labels_url":"https://api.github.com/repos/thinkjs/thinkjs/issues/1251/labels{/name}","comments_url":"https://api.github.com/repos/thinkjs/thinkjs/issues/1251/comments","events_url":"https://api.github.com/repos/thinkjs/thinkjs/issues/1251/events","html_url":"https://github.com/thinkjs/thinkjs/issues/1251","id":363376506,"node_id":"MDU6SXNzdWUzNjMzNzY1MDY=","number":1251,"title":"初学者,新建了一个restful Api的问题","user":{"login":"wenner","id":157351,"node_id":"MDQ6VXNlcjE1NzM1MQ==","avatar_url":"https://avatars1.githubusercontent.com/u/157351?v=4","gravatar_id":"","url":"https://api.github.com/users/wenner","html_url":"https://github.com/wenner","followers_url":"https://api.github.com/users/wenner/followers","following_url":"https://api.github.com/users/wenner/following{/other_user}","gists_url":"https://api.github.com/users/wenner/gists{/gist_id}","starred_url":"https://api.github.com/users/wenner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wenner/subscriptions","organizations_url":"https://api.github.com/users/wenner/orgs","repos_url":"https://api.github.com/users/wenner/repos","events_url":"https://api.github.com/users/wenner/events{/privacy}","received_events_url":"https://api.github.com/users/wenner/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-09-25T01:25:55Z","updated_at":"2018-09-25T01:50:46Z","closed_at":"2018-09-25T01:50:46Z","author_association":"NONE","body":"## DESC\r\n通过官方文档新建了一个 resuful api  \r\n\r\n> thinkjs controller test -r\r\n\r\n然后我按文档修改了router\r\n\r\n> ['/test/:id?', 'rest'], // 第三种方式\r\n\r\n然后再次\r\n\r\n> npm start\r\n\r\n访问对应的url\r\n\r\n>   think-router matchedRule: {\"match\":{\"keys\":[{\"name\":\"id\",\"prefix\":\"/\",\"delimiter\":\"/\",\"optional\":true,\"repeat\":false,\"partial\":false,\"asterisk\":false,\"pattern\":\"[^\\\\/]+?\"}]},\"path\":\"test\",\"method\":\"REST\",\"options\":{},\"query\":{}} +3s\r\n  think-router RouterParser: path=/test, module=, controller=test, action=get, query={} +1ms\r\n\r\n这个说明应该是路由生效了...然后后面就出现了错误\r\n\r\n> { Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password: YES)\r\n\r\n这个应该是连接mysql的问题....可是我只是个测试..不需要这些...\r\n\r\n我想..是不是吧这个注释掉就可以....然后我又找文档...并不知道去那找...包括 src/config/extend.js , 包括config....\r\n我吧config中的注释掉..报错..吧extend中的注释掉..还是报错\r\n\r\n然后发现,默认的index哪里是没有问题的..那么一定这个新建的controller发生的问题...\r\n看rest.js...吧constructor中注释掉\r\n\r\n>    //this.modelInstance = this.model(this.resource);\r\n\r\n然后再次访问...getAction的错误\r\n\r\n> Cannot read property 'select' of undefined\r\n\r\n\r\n那么,想问一下...我该怎么做?\r\n比如我就像实现一个 到对应的action返回一段json...这种呢:(\r\n\r\n\r\n\r\n### ENV\r\n\r\nOS Platform: win10 professinal\r\n\r\nNode.js Version: v10.3.0\r\n\r\nThinkJS Version:  2.2.5\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/thinkjs/thinkjs/issues/comments/424180749","html_url":"https://github.com/thinkjs/thinkjs/issues/1251#issuecomment-424180749","issue_url":"https://api.github.com/repos/thinkjs/thinkjs/issues/1251","id":424180749,"node_id":"MDEyOklzc3VlQ29tbWVudDQyNDE4MDc0OQ==","user":{"login":"lizheming","id":424491,"node_id":"MDQ6VXNlcjQyNDQ5MQ==","avatar_url":"https://avatars2.githubusercontent.com/u/424491?v=4","gravatar_id":"","url":"https://api.github.com/users/lizheming","html_url":"https://github.com/lizheming","followers_url":"https://api.github.com/users/lizheming/followers","following_url":"https://api.github.com/users/lizheming/following{/other_user}","gists_url":"https://api.github.com/users/lizheming/gists{/gist_id}","starred_url":"https://api.github.com/users/lizheming/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lizheming/subscriptions","organizations_url":"https://api.github.com/users/lizheming/orgs","repos_url":"https://api.github.com/users/lizheming/repos","events_url":"https://api.github.com/users/lizheming/events{/privacy}","received_events_url":"https://api.github.com/users/lizheming/received_events","type":"User","site_admin":false},"created_at":"2018-09-25T01:50:46Z","updated_at":"2018-09-25T01:50:46Z","author_association":"CONTRIBUTOR","body":"RESTful API usually relates with database, so we put database handle in CURD ad default behavior. If you want create RESTful URL without it, just don't extend `rest.js` in your controller.\r\n\r\n```js\r\nmodule.exports = class extends think.Controller {\r\n  getAction() {\r\n    return this.success('getAction');\r\n  }\r\n  postAction() {\r\n    return this.success('postAction');\r\n  }\r\n  putAction() {\r\n    return this.success('putAction');\r\n  }\r\n  deleteAction() {\r\n    return this.success('deleteAction');\r\n  }\r\n}\r\n\r\n\r\n```"}}
{"actor":{"display_login":"lizheming"}}