提问人:jtlovato2 提问时间:11/16/2023 最后编辑:jabaajtlovato2 更新时间:11/16/2023 访问量:17
Heroku 上的权限被拒绝
Permission Denied On Heroku
问:
我一直在创建一个托管在 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是可以的并且是最新的,但如果需要,我也可以发布它们。
我目前只是想让它成为当您以管理员身份登录并可以查看某些产品时显示一个新屏幕。 任何帮助都值得赞赏,谢谢。
答: 暂无答案
评论
backend/server.js
node backend/server.js
#!/usr/bin/env node
sh