简体   繁体   English

为什么我的 json-server 找不到图像?

[英]Why my json-server can't find the images?

I use json-server for my Angular app.我将 json-server 用于我的 Angular 应用程序。 I created 4 images in the specified directory but I get this error message:我在指定目录中创建了 4 个图像,但收到以下错误消息:

GET /images/plan1.png 404 1.579 ms - 2
GET /images/plan2.png 404 1.950 ms - 2
GET /images/plan3.png 404 2.078 ms - 2
GET /images/plan4.png 404 2.347 ms - 2

Why this happens when the images are existing?为什么当图像存在时会发生这种情况? I also noticed that the images aren't accessible from localhost:3000/ through my browser too?我还注意到图像也无法通过我的浏览器从localhost:3000/访问? Why?为什么?

I had 4 other images there before, and they were working well.我之前在那里有其他 4 张图片,它们运行良好。

Did you provide path to static files?您是否提供了 static 文件的路径?

https://github.com/typicode/json-server#api https://github.com/typicode/json-server#api

const jsonServer = require('json-server');
const app = jsonServer.create();
const middlewares = jsonServer.defaults({static: 'your-path'});

app.use(middlewares);

But since you told that it worked before with different images I assume you had to set that...it stops working just after you replace images?但是,既然你告诉过它之前可以使用不同的图像,我假设你必须设置它......它在你替换图像后停止工作?

I had been using my json-server on one computer and then had to move my project to a different computer and had to set up my json-server all over again.我一直在一台计算机上使用我的 json-server,然后不得不将我的项目移动到另一台计算机上,并且不得不重新设置我的 json-server。 I was getting the same error I think.我遇到了同样的错误。 Finally, I realized, when setting up my json-server again, I hadn't put my "images" folder in the "public" folder.最后,我意识到,当我再次设置我的 json-server 时,我没有将我的“images”文件夹放在“public”文件夹中。 Once I did that, everything worked.一旦我这样做了,一切都会奏效。 I don't know if this is the same issue as yours but thought I'd share in case.我不知道这是否与您的问题相同,但我想以防万一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM