Get other file data from mongo
This commit is contained in:
parent
b59f4d5f9f
commit
120fbaccd4
|
@ -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]
|
||||
|
|
|
@ -35,6 +35,7 @@ export class FileStorage {
|
|||
}
|
||||
|
||||
_getDataFromFile (reqPath) {
|
||||
reqPath = reqPath.split('/').pop()
|
||||
if (reqPath === '') {
|
||||
return Promise.resolve(this.data)
|
||||
} else if (reqPath === 'resume') {
|
||||
|
|
|
@ -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
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue