qotnews/readerserver/main.js

37 lines
955 B
JavaScript
Raw Normal View History

const port = 33843;
2019-08-21 03:49:06 +00:00
const express = require('express');
const app = express();
2020-11-10 01:56:21 +00:00
const simple = require('./scraper/simple');
2020-11-17 02:50:31 +00:00
const headless = require('./scraper/headless');
2019-08-21 03:49:06 +00:00
app.use(express.urlencoded({ extended: true }));
2020-11-10 01:56:21 +00:00
app.get('/', (req, res) => {
2020-11-17 02:50:31 +00:00
const routes = [
'/simple',
'/simple/details',
'/headless',
'/headless/details',
'/headless/comments'
];
2020-11-10 01:56:21 +00:00
const html = routes.map(route => `
<form method="POST" action="${route}" accept-charset="UTF-8">
<fieldset>
<legend>route: POST ${route}</legend>
<input name="url">
<button type="submit">SUBMIT</button>
</fieldset>
</form>`).join('<hr />');
res.send(html);
});
2020-11-17 02:50:31 +00:00
app.post('/simple/', simple.scrape);
app.post('/simple/details', simple.details);
app.post('/headless', headless.scrape);
app.post('/headless/details', headless.details);
app.post('/headless/comments', headless.comments);
2019-08-21 03:49:06 +00:00
app.listen(port, () => {
console.log(`Example app listening on port ${port}!`);
});