From 120fbaccd498ba52bfaf21a12e0786c6c20c2cbe Mon Sep 17 00:00:00 2001 From: LordMathis Date: Mon, 30 Dec 2019 12:39:44 +0100 Subject: [PATCH] Get other file data from mongo --- src/utils/serverRender.js | 2 +- src/utils/storage/file.js | 1 + src/utils/storage/mongo.js | 17 ++++++++++------- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/utils/serverRender.js b/src/utils/serverRender.js index c74fea8..7b9bc2a 100644 --- a/src/utils/serverRender.js +++ b/src/utils/serverRender.js @@ -27,7 +27,7 @@ export class ServerRenderer { ) res.status(404).send(renderFullPage(markup, head, {}, config)) } else { - const promise = this.dataHolder.getData(req.path.split('/').pop()) + const promise = this.dataHolder.getData(req.path) promise.then((data) => { const context = [data, config] diff --git a/src/utils/storage/file.js b/src/utils/storage/file.js index 411b282..8fdc21c 100644 --- a/src/utils/storage/file.js +++ b/src/utils/storage/file.js @@ -35,6 +35,7 @@ export class FileStorage { } _getDataFromFile (reqPath) { + reqPath = reqPath.split('/').pop() if (reqPath === '') { return Promise.resolve(this.data) } else if (reqPath === 'resume') { diff --git a/src/utils/storage/mongo.js b/src/utils/storage/mongo.js index 9883691..42a9a93 100644 --- a/src/utils/storage/mongo.js +++ b/src/utils/storage/mongo.js @@ -53,7 +53,7 @@ export class MongoStorage { } getData (reqPath) { - if (reqPath === '') { + if (reqPath === '/') { const data = { posts: [], other: {} @@ -63,24 +63,27 @@ export class MongoStorage { this._getOther('about'), this._getAllPosts() ]).then((res) => { - data.other.about = res[0].body + data.other.about = res[0].data data.posts = res[1].map((post) => { delete post.body return post }) return data }) - } else if (reqPath === 'resume') { - return Promise.resolve({}) + } else if (reqPath.startsWith('/post')) { + return this._getPost(reqPath.split('/').pop()) } else { - return this._getPost(reqPath) + return this._getOther(reqPath.split('/').pop()) } } _getOther (filename) { return new Promise((resolve, reject) => { - this.Other.findOne({ filename: filename }, (err, res) => { - err ? reject(err) : resolve(res) + this.Other.findOne({ filename: filename }, (err, data) => { + err ? reject(err) : resolve({ + type: filename, + data: data.body + }) }) }) }