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))
} else {
const promise = this.dataHolder.getData(req.path.split('/').pop())
const promise = this.dataHolder.getData(req.path)
promise.then((data) => {
const context = [data, config]

View File

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

View File

@ -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
})
})
})
}