Heroku 上的权限被拒绝

Permission Denied On Heroku

提问人:jtlovato2 提问时间:11/16/2023 最后编辑:jabaajtlovato2 更新时间:11/16/2023 访问量:17

问:

我一直在创建一个托管在 Heroku 上的应用程序,添加新组件后,Heroku 无法构建并给出错误

app[web.1]: sh: 1: backend/server.js: Permission denied heroku[web.1]: Process exited with status 126 heroku[web.1]: State changed from starting to crashed heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=tempest-5a9f886e3f9d.herokuapp.com 

创建新组件时,我没有碰服务器.js,我已经倒在了新组件上,但我不确定出了什么问题。在编译时,Heroku 首先说它是 Built,但进入实际页面时,我收到应用程序错误并显示 503 错误。

这是我添加的代码。同样,在添加此代码之前,我能够很好地推送和构建。

列表产品屏幕.js

import React, { useContext, useEffect, useReducer } from "react";
import axios from "axios";
import { Link, useLocation } from "react-router-dom";
import { Store } from "../Store";
import LoadingBox from "../components/LoadingBox";
import MessageBox from "../components/MessageBox";

const reducer = (state, action) => {
  switch (action.type) {
    case "FETCH_REQUEST":
      return { ...state, loading: true };
    case "FETCH_SUCCESS":
      return {
        ...state,
        products: action.payload.products,
        page: action.payload.page,
        pages: action.payload.pages,
        loading: false,
      };
    case "FETCH_FAIL":
      return { ...state, loading: false, error: action.payload };

    default:
      return state;
  }
};

export default function ListProductsScreen() {
  const [{ loading, error, products, pages }, dispatch] = useReducer(reducer, {
    loading: true,
    error: "",
  });

  const { search, pathname } = useLocation();
  const sp = new URLSearchParams(search);
  const page = sp.get("page") || 1;

  const { state } = useContext(Store);
  const { userInfo } = state;

  useEffect(() => {
    const fetchData = async () => {
      try {
        const { data } = await axios.get(`/api/products/admin?page=${page} `, {
          headers: { Authorization: `Bearer ${userInfo.token}` },
        });

        dispatch({ type: "FETCH_SUCCESS", payload: data });
      } catch (err) {}
    };
    fetchData();
  }, [page, userInfo]);

  return (
    <div>
      <h1>Products</h1>
      {loading ? (
        <LoadingBox></LoadingBox>
      ) : error ? (
        <MessageBox variant='danger'>{error}</MessageBox>
      ) : (
        <>
          <table className='table'>
              <thead>
              <tr>
                <th>ID</th>
                <th>NAME</th>
                <th>PRICE</th>
                <th>CATEGORY</th>
                <th>BRAND</th>
              </tr>
            </thead>
            <tbody>
              {products.map((product) => (
                <tr key={product._id}>
                  <td>{product._id}</td>
                  <td>{product.name}</td>
                  <td>{product.price}</td>
                  <td>{product.category}</td>
                  <td>{product.brand}</td>
                </tr>
              ))}
            </tbody>
          </table>
          <div>
            {[...Array(pages).keys()].map((x) => (
              <Link
                className={x + 1 === Number(page) ? "btn text-bold" : "btn"}
                key={x + 1}
                to={`/admin/products?page=${x + 1}`}
              >
                {x + 1}
              </Link>
            ))}
          </div>
        </>
      )}
    </div>
  );
}

应用.js

     <Route
             path='/admin/products'
             element={
               <AdminRoute>
                 <ListProductsScreen />
               </AdminRoute>
             }
           ></Route>

产品路由.js

productRouter.get(
  '/admin',
  isAuth,
  isAdmin,
  expressAsyncHandler(async (req, res) => {
    const { query } = req;
    const page = query.page || 1;
    const pageSize = query.pageSize || PAGE_SIZE;

    const products = await Product.find()
      .skip(pageSize * (page - 1))
      .limit(pageSize);
    const countProducts = await Product.countDocuments();
    res.send({
      products,
      countProducts,
      page,
      pages: Math.ceil(countProducts / pageSize),
    });
  })
);

我还确保我的 Procfile 和package.json是可以的并且是最新的,但如果需要,我也可以发布它们。

我目前只是想让它成为当您以管理员身份登录并可以查看某些产品时显示一个新屏幕。 任何帮助都值得赞赏,谢谢。

JavaScript Reactjs heroku

评论

0赞 jabaa 11/16/2023
看起来你正在尝试运行.这是正确的吗?它是否具有可执行权限?它是否包含正确的shebang?你真的想跑吗?backend/server.jsnode backend/server.js
0赞 jtlovato2 11/16/2023
我确实运行后端/服务器.js,并且我能够在此代码到位之前运行。它都具有所有可执行权限,我正在运行节点后端/服务器.js
0赞 jabaa 11/16/2023
你有文件的第一行吗?否则,该文件不能由 运行。#!/usr/bin/env nodesh

答: 暂无答案