striven-editor

Maintained and contributed to an open source WYSIWYG editor as an internship project that made it to production and was adopted by the company I was working at.
git clone https://unitehenry.com/git/striven-editor.git
Log | Files | Refs | README | LICENSE

metaserver.js (1191B)


      1 const express = require('express');
      2 const app = express();
      3 const PORT = 4200;
      4 const path = require('path');
      5 const got = require('got');
      6 const bodyParser = require('body-parser');
      7 const cors = require('cors');
      8 
      9 const metascraper = require('metascraper')([
     10     require('metascraper-description')(),
     11     require('metascraper-image')(),
     12     require('metascraper-title')(),
     13     require('metascraper-url')()
     14 ]);
     15 
     16 app.use(cors());
     17 app.use(bodyParser.json());
     18 app.use(bodyParser.urlencoded({ extended: true }));
     19 app.use(express.static(path.join(__dirname, 'dist')));
     20 
     21 app.post('/meta', (req, res) => {
     22     const targetUrl = req.body.targetUrl;
     23     targetUrl && console.log('Fetching meta data from ', targetUrl);
     24 
     25     if(targetUrl) {
     26         (async () => {
     27             const { body: html, url } = await got(targetUrl);
     28             const metadata = await metascraper({ html, url });
     29 
     30             console.log('Sending meta data: \n', metadata);
     31             res.send(metadata);
     32         })()
     33     } else {
     34         console.log('Sending error 400 back.');
     35         res.sendStatus(400);
     36     }
     37 })
     38 
     39 app.listen(PORT, () => console.log(`Meta server open on port: ${PORT}`));