gpt4 book ai didi

javascript - json-server db.json 中 '/' 的路径

转载 作者:行者123 更新时间:2023-12-05 00:35:40 25 4
gpt4 key购买 nike

我用 server-json要拥有一个假 API,我在 data.json 中有路径“playbook/active”

"playbook/active": [{
"description": "This playbook will install haproxy",
"name": "Testing playbook 3",
"tag": [
"loadbalancer",
"charge"
],
"path": "/etc/ansible/haproxy.yml",
"type": "action",
"id": "4bb107be-9efe-11e9-b3e5-bc5ff4901aa5"
},
{
"path": "google.com",
"description": "This is the playbook before execution",
"tag": [
"webserver",
"tomcat"
],
"id": "faa746b4-9cb7-11e9-9b94-bc5ff4901aa5",
"name": "mysql"
}
]

但我有这个错误

Error: Oops, found / character in database property 'playbook/active'.



我更改为“剧本/事件”但同样的错误

最佳答案

提供完整的答案(展示示例)
配置 db.jsonroutes.json可以为您解决问题:

  • db.json

  • {
    "playbookActive": [
    {
    "id": 1,
    "name": "Active Playbook 1",
    "description": "Description 1"
    },
    {
    "id": 2,
    "name": "Active Playbook 2",
    "description": "Description 2"
    }
    ]
    }
    路线.json
    {
    "/playbook/active": "/playbookActive",
    "/playbook/active/:id": "/playbookActive/:id"
    }

    Note: the mapping in routes.json is goes like this: [expanded/endpoint]: aliasEndpoint where aliasEndpoint should match the one from db.json.


    包.json
    {
    ...
    "scripts": {
    "api": "json-server [path-to-db.json] --routes [path-to-routes.json] --no-cors=false"
    },
    ...
    }
    验证启动时的路由(来自 npm run api 的日志):
    Resources
    http://localhost:3000/playbookActive

    Other routes
    /playbook/active -> /playbookActive
    /playbook/active/:id -> /playbookActive/:id

    Home
    http://localhost:3000

    例子
    GET → http://localhost:3000/playbook/active
    响应包含一个包含所有事件剧本的列表:
    [
    {
    "id": 1,
    "name": "Active Playbook 1",
    "description": "Description 1"
    },
    {
    "id": 2,
    "name": "Active Playbook 2",
    "description": "Description 2"
    }
    ]
    GET → http://localhost:3000/playbook/active/2
    响应包含匹配 id=2 的事件剧本:
    {
    "id": 2,
    "name": "Active Playbook 2",
    "description": "Description 2"
    }

    关于javascript - json-server db.json 中 '/' 的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57005091/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com