From ba50455abd44b9031df086c8c473d96cd3abd0f3 Mon Sep 17 00:00:00 2001 From: Badri Sunderarajan Date: Fri, 8 May 2020 15:43:34 +0530 Subject: [PATCH] Server: save incoming JSON to file instead of discarding This is the first step in actually saving and processing the thing --- server.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/server.js b/server.js index 4a40ff4..6a3cc5d 100644 --- a/server.js +++ b/server.js @@ -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