Archived
first step -- tolto palette
This commit is contained in:
+51
-10
@@ -1,14 +1,55 @@
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
const bodyParser = require('body-parser');
|
||||
const low = require('lowdb');
|
||||
const FileAsync = require('lowdb/adapters/FileAsync');
|
||||
const app = express(); // app is an instance of express
|
||||
|
||||
app.use(express.static(__dirname + '/build'));
|
||||
app.use(bodyParser.urlencoded({ extended: false })) // parse application/x-www-form-urlencoded
|
||||
app.use(bodyParser.json()) // parse application/json
|
||||
app.use(express.static(__dirname + '/build')); // serve static build site
|
||||
app.post('/test',(req,res)=>{
|
||||
res.send(req.body);
|
||||
})
|
||||
|
||||
app.get('/test/:id', (req, res) => {
|
||||
// req.params.id
|
||||
// new wiki().page(req.params.id)
|
||||
// .then(page => page.fullInfo())
|
||||
// .then(parsed => res.send(parsed));
|
||||
res.send({ok:req.params.id});
|
||||
});
|
||||
// Create database instance and start server
|
||||
// const adapter = new FileAsync(__dirname + '/db.json');
|
||||
low(new FileAsync(__dirname + '/db.json'))
|
||||
.then(db => {
|
||||
// DATABASE ROUTES
|
||||
|
||||
app.listen(8000, () => console.log('listen on 8000'));
|
||||
// GET /videolog
|
||||
app.get('/videolog', (req, res) => {
|
||||
const post = db
|
||||
.get('videos')
|
||||
// .find({ id: req.params.id })
|
||||
.value();
|
||||
res.send(post);
|
||||
});
|
||||
|
||||
// POST /videolog
|
||||
app.post('/videolog', (req, res) => {
|
||||
db.get('videos')
|
||||
.push(req.body)
|
||||
.last()
|
||||
.update('timesWatched', n => n + 1 )
|
||||
.write()
|
||||
.then(post => res.send(post)); // non funziona minimamente lol
|
||||
});
|
||||
|
||||
// Set db default values
|
||||
return db
|
||||
.defaults({
|
||||
videos: [
|
||||
// {
|
||||
// videoId: '',
|
||||
// timesWatched: 0,
|
||||
// prevalentReason: '',
|
||||
// lastSelected: new Date()
|
||||
// }
|
||||
]
|
||||
})
|
||||
.write();
|
||||
})
|
||||
.then(() => {
|
||||
app.listen(8000, () => console.log('listen on 8000')); // bind to port 8000 as required from specs
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user