【问题标题】:JavaScript file net::ERR_ABORTED 404 (Not Found)JavaScript 文件 net::ERR_ABORTED 404(未找到)
【发布时间】:2020-12-30 03:00:51
【问题描述】:

我想为我的小型 Firebase 网络应用添加一些支付选项的后端功能。我的项目具有以下结构。

project 
| functions (cloud functions here)
| --server.js
| static (all JavaScript files for frontend, css, images)
| --style.css
| --index.js
| --images
| index.html
| other HTML files
 

这是我的server.js 文件中的内容。我的所有 JavaScript 文件都收到了 net::ERR_ABORTED 404 (Not Found)。我应该在这里做什么?

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

app.set('view engine', 'ejs');
app.use(express.static('../../project'));

我注意到以下两个可能对我有帮助的帖子,我从那里尝试了一些最佳答案,但仍然卡住,实际上不明白问题出在哪里以及必须做什么。

JS file gets a net::ERR_ABORTED 404 (Not Found)

How do I use HTML as the view engine in Express?

【问题讨论】:

  • 我想更好地了解您的项目。您能否提供使用您的 server.js 的前端文件?

标签: javascript node.js firebase express google-cloud-functions


【解决方案1】:

我在这里注意到的问题是这一行app.use(express.static('../../project')); 您正在做的是将文件夹 project 设置为公开。您的 JS 文件位于静态文件夹中,并且不会被读取。我建议采用以下结构:

project 
  server.js
  static (folder)
    HTML (folder for all HTML files)
    css (folder for all css files)
    js (folder for all js files)

然后在您的server.js 文件中:

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

app.set('view engine', 'ejs');
app.use(express.static('./static'));

【讨论】:

    猜你喜欢
    • 2020-11-03
    • 1970-01-01
    • 2022-12-04
    • 2020-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-11
    相关资源
    最近更新 更多