web服务器找不到资源404,Nodejs服务器:无法加载资源:服务器响应状态为404(未找到)(Nodejs server: Failed to load resource: the server ...

Nodejs服务器:无法加载资源:服务器响应状态为404(未找到)(Nodejs server: Failed to load resource: the server responded with a status of 404 (Not Found))

我在节点中设置了一个Web服务器。

var app = express();

app.use(express.static(PUBLIC_PATH));

server = require('http').createServer(app),

io = require('socket.io').listen(server);

我将公共路径设置为我的应用程序的根公用文件夹,我保留了我的前端,所以当部署服务器时,它是/ app / public

当我尝试打开页面时,我在chrome的控制台中看到了这一点

我无法加载资源:服务器响应状态为404(未找到)

有问题的文件是app.js,它位于我的公共文件夹中。 我确实看到Web服务器对该特定文件的请求

2015-04-04T15:43:04.208178 + 00:00 heroku [router]:at = info method = GET path =“/ style.css”host = hive-badescuga.herokuapp.com request_id = 2be0334e-e968-4397-8c2e -9c65c85fea22 fwd =“188.25.247.211”dyno = web.1 connect = 1ms service = 6ms status = 304 bytes = 236

2015-04-04T15:43:04.203415 + 00:00 heroku [router]:at = info method = GET path =“/ app.js”host = hive-badescuga.herokuapp.com request_id = fc8c529c-7641-4df2-9b13 -5fee9e1af365 fwd =“188.25.247.211”dyno = web.1 connect = 1ms service = 7ms status = 404 bytes = 217

2015-04-04T15:43:09.152566 + 00:00 heroku [router]:at = info method = GET path =“/ style.css”host = hive-badescuga.herokuapp.com request_id = b89ded8e-5433-4b57-8c80 -c2e7407d31b0 fwd =“188.25.247.211”dyno = web.1 connect = 1ms service = 6ms status = 304 bytes = 236

问题是什么?

UPDATE

当我进一步调试时,我看到与我的app.js(无法加载)在同一根中的css被加载。 这是我的HTML:

所以style.css确实被加载而app.js没有(因为它找不到),并且它们在同一个文件夹中。

I have a web server setted up in node.

var app = express();

app.use(express.static(PUBLIC_PATH));

server = require('http').createServer(app),

io = require('socket.io').listen(server);

i set the public path to my app's root public folder, where i keep my frontend, so when the server is deployed, it's /app/public

When i try to open a page, i see this in chrome's console

i Failed to load resource: the server responded with a status of 404 (Not Found)

The file in question is app.js which is located in my public folder. I do see requests from the web server for that certain file

2015-04-04T15:43:04.208178+00:00 heroku[router]: at=info method=GET path="/style.css" host=hive-badescuga.herokuapp.com request_id=2be0334e-e968-4397-8c2e-9c65c85fea22 fwd="188.25.247.211" dyno=web.1 connect=1ms service=6ms status=304 bytes=236

2015-04-04T15:43:04.203415+00:00 heroku[router]: at=info method=GET path="/app.js" host=hive-badescuga.herokuapp.com request_id=fc8c529c-7641-4df2-9b13-5fee9e1af365 fwd="188.25.247.211" dyno=web.1 connect=1ms service=7ms status=404 bytes=217

2015-04-04T15:43:09.152566+00:00 heroku[router]: at=info method=GET path="/style.css" host=hive-badescuga.herokuapp.com request_id=b89ded8e-5433-4b57-8c80-c2e7407d31b0 fwd="188.25.247.211" dyno=web.1 connect=1ms service=6ms status=304 bytes=236

What is the problem?

UPDATE

As i'm debugging further i see that a css in the same root as my app.js (that can't be loaded), gets loaded. Here is my html:

so style.css does get loaded while app.js doesn't (because it can't be found), and they are in the same folder.

原文:https://stackoverflow.com/questions/29448475

更新时间:2019-12-31 17:28

最满意答案

我不知道它是否会有所帮助,但可能你应该写:process.env.PUBLIC_PATH。 另外,我不知道你是否有这个:var express = require('express');

我有这个:app.use(express.static(path.join(__ dirname,'views')));

All is fixed, had the app.js git ignored so it worked locally but it wasn't uploaded.

相关问答

您的文件不在jsp文件夹下 ,这是找不到它的原因。 你必须再回去1个文件夹试试这个:

Your files are not under the jsp folder that's why it is not found. You have to go back again 1 folder Try this:

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://jav

...

我不知道它是否会有所帮助,但可能你应该写:process.env.PUBLIC_PATH。 另外,我不知道你是否有这个:var express = require('express'); 我有这个:app.use(express.static(path.join(__ dirname,'views'))); All is fixed, had the app.js git ignored so it worked locally but it wasn't uploaded.

这些消息只是调试输出:Jetbrains IDE Chrome扩展程序检查是否存在js.map文件,如果没有找到,则打印一条消息。 这种检查的原因是用于压缩/转换代码的一些工具不会生成调试器需要定位源映射所需的// sourceMapUrl注释,因此它会检查映射存在的一些默认位置。 因此,这些消息不表示任何错误并且不会造成任何伤害,可以安全地忽略它们。 此调试输出将在下一个插件更新中过滤掉 - 修复正在进行中 These messages are just the debug output: th

...

更改您的路线如下: root 'items#index'

resources :items do

post :add_to_cart, on: :member

end

我将add_to_cart请求转换为post而不是get因为您正在触发post请求并将路由定义为get 。 另外,我删除了重复路由定义的resources :items和 Change your routes as below: root 'items#index'

resources :items

...

你已经在app root / public中定义了公共目录 app.use(express.static(__dirname + '/public'));

所以你必须使用: ./css/main.css

you have defined the public dir in app root/public app.use(express.static(__dirname + '/public'));

so you have to use: ./css/main.css

我没有使用任何插件。 使用API的基本javascript谷歌地图。 我已经回答了我的第一篇文章,但问题是来源。 网址应为/scripts/green.png或scripts / green.png。 我以为我之前尝试过这些,但由于某种原因没有让那些工作。 有时在Visual Studio Rebuild中不起作用。 必须先做清洁而不是建造。 也许这是第一次出现问题。 不知道。 但现在一切顺利! I am not using any plugin. Basic javascript google

...

想出这个我不得不改变我的服务器配置root尝试改变 nginx root /home/deploy/app_name/public; to /home/deploy/app_name/current/public;

在nginx配置文件/ etc / nginx / sites-enabled / default中。 Figured this out out i had to change my server configuration root Try changing nginx root

...

删除应用程序的整个Android部分: cordova platform remove android

并再次添加: cordova platform add android

解决了这个问题,这对我来说仍然是个谜。 也许从科尔多瓦的早期版本出现了一些问题,与当前的科尔多瓦版本不兼容。 Removing the whole Android part of the application with: cordova platform remove android

and adding it ag

...

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值