簡體   English   中英

未找到 Heroku 節點應用程序 404,未加載前端 js 文件或 css

[英]Heroku node app 404 not found, doesn't load front end js files or css

所以我有一個在本地主機上運行良好的簡單應用程序,但是當我將它部署到 Heroku 時,前端文件不會加載,所以我得到了沒有樣式或功能的原始 html。 瀏覽器目錄是所有未加載的文件所在的位置。 我將把我的服務器文件和 package.json 放在下面。 我真的很感激任何幫助。 謝謝!

服務器.js

const path = require('path');

    const http = require('http');
    const server = http.createServer();

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

    server.on('request', app);

    server.listen(process.env.PORT || 5000)

    app.use(express.static(path.join(__dirname, 'Browser')));

    app.get('/', function (req, res) {
        res.sendFile(path.join(__dirname, 'chess.html'));
    });

包.JSON

{
      "name": "Chess",
      "version": "1.0.0",
      "description": "One player chess against an AI",
      "main": "server.js",
      "scripts": {
        "start": "node server.js"
      },
      "engines": {
        "node": ">=4.0.0"
      },
      "dependencies": {
        "express": ">=4.13.3"
      }
    }

文件結構

_Chessjs
+-- app.json
+-- package.json
+-- Procfile
+-- chess.html
+-- server.js
+-- _Broswer
|   +-- ai.js
|   +-- board.js
|   +-- game.js
|   +-- piece.js
|   +-- style.css
+-- _node_modules

您將server.js ES6文件轉換為ES5? 如果您,dist文件的路徑在哪里?

我想看到一個層次結構。

確保將以下內容添加到 package.json 中的腳本中:

"heroku-postbuild": "cd client && npm install --only=dev && npm install && npm run build"

否則,即使修復了您的 MERN 應用程序的任何問題,您也可能仍然會收到這些錯誤消息。

更多信息請訪問以下鏈接: https : //github.com/heroku/heroku-buildpack-nodejs/issues/589

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM