Server: save incoming JSON to file instead of discarding
This is the first step in actually saving and processing the thing
This commit is contained in:
parent
50f8002d45
commit
ba50455abd
1 changed files with 10 additions and 0 deletions
10
server.js
10
server.js
|
@ -1,6 +1,8 @@
|
||||||
const express = require('express')
|
const express = require('express')
|
||||||
const bodyParser = require('body-parser')
|
const bodyParser = require('body-parser')
|
||||||
const { vueRenderer } = require('@doweb/vuexpress')
|
const { vueRenderer } = require('@doweb/vuexpress')
|
||||||
|
const slugify = require('underscore.string/slugify')
|
||||||
|
const fs = require('fs')
|
||||||
|
|
||||||
const app = express()
|
const app = express()
|
||||||
|
|
||||||
|
@ -83,6 +85,14 @@ app.post('/fetch/', (req, res) => {
|
||||||
if (post.virtuals.previewImage) {
|
if (post.virtuals.previewImage) {
|
||||||
post.featuredImage = 'https://cdn-images-1.medium.com/max/800/' + post.virtuals.previewImage.imageId
|
post.featuredImage = 'https://cdn-images-1.medium.com/max/800/' + post.virtuals.previewImage.imageId
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set ID
|
||||||
|
if (!post.slug) {
|
||||||
|
post.slug = slugify(post.title)
|
||||||
|
}
|
||||||
|
|
||||||
|
// save to disk
|
||||||
|
fs.writeFileSync(`${post.slug}.json`, JSON.stringify(json), 'utf-8')
|
||||||
}
|
}
|
||||||
|
|
||||||
// render the final post
|
// render the final post
|
||||||
|
|
Loading…
Reference in a new issue