List classes and dummy forum data

This commit is contained in:
Elijah Lucian
2018-03-13 23:56:23 -06:00
parent 9e88608877
commit 5107775913
7 changed files with 2006 additions and 282 deletions
+31
View File
@@ -3,12 +3,42 @@ const cheerio = require('cheerio');
const express = require('express')
const app = express()
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
next();
});
app.use('/', express.static('dist'))
app.use('/psboard', express.static('dist/shit/psboard.html'))
app.get('/hello', (req, res) => {
res.send('Hello World!')
})
app.get('/api/data/psboard', (req, res) => {
request('http://localhost:3000/psboard', (error, response, html) => {
if (!error && response.statusCode == 200) {
const $ = cheerio.load(html);
let psboard = [];
$('.F0XO1GC-p-w').children().each((i, elem) => {
psboard[i] = {
subject: $(elem).find('.F0XO1GC-p-Q').text(),
author: $(elem).find('.F0XO1GC-rb-b').text(),
last_update: $(elem).find('.F0XO1GC-rb-g').children().attr('title'),
number_of_posts: $(elem).find('.F0XO1GC-rb-r').eq(0).text(),
number_of_views: $(elem).find('.F0XO1GC-rb-r').eq(1).text(),
user_pic: $(elem).find('.gwt-Image').attr('src')
}
});
res.setHeader('Content-Type', 'application/json');
res.send(psboard);
}
})
})
app.get('/api/data/classes', (req, res) => {
request('https://my.protospace.ca/school', (error, response, html) => {
if (!error && response.statusCode == 200) {
@@ -29,6 +59,7 @@ app.get('/api/data/classes', (req, res) => {
});
})
app.listen(3000, function () {
console.log('Example app listening on port 3000!')
})