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:
Badri Sunderarajan 2020-05-08 15:43:34 +05:30
parent 50f8002d45
commit ba50455abd

View file

@ -1,6 +1,8 @@
const express = require('express')
const bodyParser = require('body-parser')
const { vueRenderer } = require('@doweb/vuexpress')
const slugify = require('underscore.string/slugify')
const fs = require('fs')
const app = express()
@ -83,6 +85,14 @@ app.post('/fetch/', (req, res) => {
if (post.virtuals.previewImage) {
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