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))
|
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]
|
||||||
|
|
|
@ -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') {
|
||||||
|
|
|
@ -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
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue