Get other file data from mongo

This commit is contained in:
LordMathis 2019-12-30 12:39:44 +01:00
parent b59f4d5f9f
commit 120fbaccd4
No known key found for this signature in database
GPG Key ID: 575849FD91CE470C
3 changed files with 12 additions and 8 deletions

View File

@ -27,7 +27,7 @@ export class ServerRenderer {
) )
res.status(404).send(renderFullPage(markup, head, {}, config)) res.status(404).send(renderFullPage(markup, head, {}, config))
} else { } else {
const promise = this.dataHolder.getData(req.path.split('/').pop()) const promise = this.dataHolder.getData(req.path)
promise.then((data) => { promise.then((data) => {
const context = [data, config] const context = [data, config]

View File

@ -35,6 +35,7 @@ export class FileStorage {
} }
_getDataFromFile (reqPath) { _getDataFromFile (reqPath) {
reqPath = reqPath.split('/').pop()
if (reqPath === '') { if (reqPath === '') {
return Promise.resolve(this.data) return Promise.resolve(this.data)
} else if (reqPath === 'resume') { } else if (reqPath === 'resume') {

View File

@ -53,7 +53,7 @@ export class MongoStorage {
} }
getData (reqPath) { getData (reqPath) {
if (reqPath === '') { if (reqPath === '/') {
const data = { const data = {
posts: [], posts: [],
other: {} other: {}
@ -63,24 +63,27 @@ export class MongoStorage {
this._getOther('about'), this._getOther('about'),
this._getAllPosts() this._getAllPosts()
]).then((res) => { ]).then((res) => {
data.other.about = res[0].body data.other.about = res[0].data
data.posts = res[1].map((post) => { data.posts = res[1].map((post) => {
delete post.body delete post.body
return post return post
}) })
return data return data
}) })
} else if (reqPath === 'resume') { } else if (reqPath.startsWith('/post')) {
return Promise.resolve({}) return this._getPost(reqPath.split('/').pop())
} else { } else {
return this._getPost(reqPath) return this._getOther(reqPath.split('/').pop())
} }
} }
_getOther (filename) { _getOther (filename) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.Other.findOne({ filename: filename }, (err, res) => { this.Other.findOne({ filename: filename }, (err, data) => {
err ? reject(err) : resolve(res) err ? reject(err) : resolve({
type: filename,
data: data.body
})
}) })
}) })
} }