Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js应用程序在本地主机上运行,但在Heroku上出现404错误_Node.js_Heroku - Fatal编程技术网

Node.js应用程序在本地主机上运行,但在Heroku上出现404错误

Node.js应用程序在本地主机上运行,但在Heroku上出现404错误,node.js,heroku,Node.js,Heroku,我不熟悉Heroku和Node.js。它在本地主机上运行良好,但在Heroku上出现此错误 404找不到 我被这个问题困扰了一个星期。我在网上搜索,但找不到有效的解决方案。我还在设置下的Heroku中添加了配置变量。在我的客户端React应用程序中,我调用此“”API以获取数据。 我的服务器完整代码: const express = require('express'); const pg = require('pg'); const app = express(); require('dot

我不熟悉Heroku和Node.js。它在本地主机上运行良好,但在Heroku上出现此错误

404找不到

我被这个问题困扰了一个星期。我在网上搜索,但找不到有效的解决方案。我还在设置下的Heroku中添加了配置变量。在我的客户端React应用程序中,我调用此“”API以获取数据。 我的服务器完整代码:

const express = require('express');
const pg = require('pg');

const app = express();
require('dotenv').config();

const pool = new pg.Pool();

const queryHandler = (req, res, next) => {
  pool.query(req.sqlQuery).then((r) => {
    return res.json(r.rows || [])
  }).catch(next)
}

app.get('/', (req, res, next) => {
  res.header("Access-Control-Allow-Origin", "*");
  res.send('Welcome  In Heroku, under "More" on the top right when in your application's dashboard, you can "View Logs" to see if it is spinning up properly and if you're getting any errors.

Make sure to setup a Procfile, which tells Heroku what to actually run on the dynos.

The syntax is easy:

dyno_name_here: cli_command_here
const express=require('express');
常数pg=需要('pg');
常量app=express();
require('dotenv').config();
const pool=新页面pool();
常量查询句柄=(请求、恢复、下一步)=>{
pool.query(req.sqlQuery).then((r)=>{
返回res.json(r.rows | |[])
}).接住(下一个)
}
app.get(“/”,(请求、恢复、下一步)=>{
res.header(“访问控制允许原点”、“*”);
res.send('Welcome在Heroku中,在应用程序仪表板右上角的“More”下,您可以“查看日志”,查看它是否正常运行以及是否出现任何错误

确保设置一个Procfile,它告诉Heroku在dynos上实际运行什么

语法很简单:


404通常意味着服务器找不到您请求的内容。因此,您的服务器已启动并正在运行,但无法获取您请求的资源。可能更多上下文有助于解决您的问题。我添加了我的服务器完整代码。我添加了Procfile文件并检查了日志。收到此错误“错误注入运行时环境:未找到捆绑包”/app/build/static/js/*.js”。请参阅:'不知道如何解决。请帮助