0

我创建了一个环回 API 并将其部署在 now.sh 上。部署后,我可以浏览目录但无法调用 API URL。我的项目结构如下:

在此处输入图像描述

包.json 文件:

{
"name": "****",
"version": "1.0.0",
"main": "server/server.js",
"engines": {
    "node": ">=6"
},
"now":{
    "name":"****",
    "alias":["****"],
    "env":{
        "MONGODB_URL":"@lbmongonew",
        "NODE_ENV":"production"
    }
},
"scripts": {
    "lint": "eslint .",
    "now:deploy":"now",
    "now:alias":"now alias",
    "now":"npm run now:deploy && npm run now:alias",
    "posttest": "npm run lint && nsp check",
    "start": "node ."
},
"dependencies": {
    "compression": "^1.0.3",
    "cors": "^2.5.2",
    "helmet": "^3.10.0",
    "loopback": "^3.22.0",
    "loopback-boot": "^2.6.5",
    "loopback-component-explorer": "^6.2.0",
    "loopback-connector-mongodb": "^4.0.0",
    "now": "^13.1.2",
    "serve-favicon": "^2.0.1",
    "strong-error-handler": "^3.0.0",
    "todo": "^1.1.0"
},
"devDependencies": {
    "eslint": "^3.17.1",
    "eslint-config-loopback": "^8.0.0"
},
"repository": {
    "type": "",
    "url": ""
},
"license": "UNLICENSED",
"description": "****"}

我的 config.production.json 文件如下:

{
"restApiRoot": "/api",
"host": "0.0.0.0",
"port": 3000,
"remoting": {
    "context": false,
    "rest": {
        "handleErrors": false,
        "normalizeHttpPath": false,
        "xml": false
    },
    "json": {
        "strict": false,
        "limit": "100kb"
    },
    "urlencoded": {
        "extended": true,
        "limit": "100kb"
    },
    "cors": false
   }}

注意:我没有更改主机和端口,因为主机是用于部署的动态主机,在 now.sh 上的每个部署中都会不断变化

这是部署后我可以浏览的目录

在此处输入图像描述

当我浏览“ https://URL/explorer ”时,出现页面未找到错误。浏览 API 时我在这里缺少什么?

4

1 回答 1

0

您使用的是now v2吗?如果是这样,您需要在部署之前now.jsonpackage.json在部署之前使用 Node Builder。

https://zeit.co/docs/v2/deployments/official-builders/node-js-now-node/

于 2019-01-31T15:33:39.930 回答