I am trying to do a GET request using Postman on .public/images/logo.png
and I can see the image on the directory on my computer, but what I get is the following error message:
GET /public/images/logo.png 404 12.420 ms - 2529
This is my imagesRouter.js
file:
imagesRouter.route('/')
//.options(cors.corsWithOptions, (req, res) => { res.sendStatus(200); })
.get(cors.cors, (req,res,next) => {
Images.find({})
.then((images) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'application/json');
res.json(images);
}, (err) => next(err))
.catch((err) => next(err));
})
And the following is my models/images.js
file:
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var ImagesSchema = new Schema({
logo: {
type: String,
default: '/public/images/logo.png'
},
header: {
type: String,
default: '/public/images/header.jpg'
}
});
var Images = mongoose.model('Image', ImagesSchema);
module.exports = Images ;
我想做的是在Angular客户端上提供图像服务,以读取一些主要的网站图像文件(例如徽标,标头等),并厌倦了将图像名称指定为键,将图像地址指定为以下值:
images.ts:
export class Images {
logo: string;
header: string;
}
image.service.ts:
@Injectable({
providedIn: 'root'
})
export class ImagesService {
constructor(private http: HttpClient,
private processHTTPMsgService: ProcessHTTPMsgService) { }
getImages(): Observable<Images> {
return this.http.get<Images>(baseURL + 'public/images')
.pipe(catchError(this.processHTTPMsgService.handleError));
}
}