无法弄清楚为什么Heroku网站会输出`cannot GET /`消息

时间:2019-05-08 10:59:44

标签: node.js github heroku

因此,每次我尝试查看我的应用时,它只会说“无法获取/” 这是代码

server.js

//Import requiered packages
const express = require('express');
const {Client} = require('pg');

//Create the conection to the postgres server
const client = new Client({
    connectionString: process.env.DATABASE_URL
});

client.connect();

//Create the express app
const bodyParser = require('body-parser');
const app = express();

// parse application/json
app.use(bodyParser.json());

//Handle a post request at /query
app.post('/query', (req, res) => {
    res.setHeader('Content-Type', 'application/json');
    console.log("Receiving request");
    if(req.body.query) {
        console.log(req.body.query);
        client.query(req.body.query, (err, r) => {
            if (err) throw err;
            rows = [];
            for(let row of r.rows){
                rows.push(row);
            }
            response = JSON.stringify(rows);
            console.log(response);
            res.end(response);
        });
    }
});


const port = process.env.PORT || 8080
//Start listening
const server = app.listen(port, function () {
   console.log("App listening at ${host}")
});

package.json

{
  "name": "haha",
  "description": "joseph = obesity > lawa",
  "main": "server.js",
  "scripts": {
    "start": "node server.js"
  },
  "dependencies": {
    "express": "4.x.x",
    "pg": "7.x.x",
    "body-parser": "1.18.x"
  }
}

我从字面上不知道出了什么问题,并且CLI中几乎没有错误。 CLI中的错误基本上与此无关,因为即使没有错误,仍然会显示“无法获取/”消息 请帮助我:(

0 个答案:

没有答案