|
|
|
@ -1,12 +1,13 @@
|
|
|
|
|
//import {NeedsApp} from './needs'
|
|
|
|
|
var NeedsApp = require('./needs')
|
|
|
|
|
|
|
|
|
|
//import PouchDB from 'pouchdb'
|
|
|
|
|
var PouchDB = require('pouchdb');
|
|
|
|
|
var { getModel } = require('./model')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//import polka from 'polka'
|
|
|
|
|
const polka = require('polka');
|
|
|
|
|
|
|
|
|
|
//import serve from 'serve-static'
|
|
|
|
|
const serve = require('serve-static')
|
|
|
|
|
|
|
|
|
|
//import m from 'mithril'
|
|
|
|
@ -14,55 +15,56 @@ var m = require('mithril')
|
|
|
|
|
//import render from 'mithril-node-render'
|
|
|
|
|
const render = require('mithril-node-render')
|
|
|
|
|
|
|
|
|
|
var items = [
|
|
|
|
|
'Apfel',
|
|
|
|
|
'Birne',
|
|
|
|
|
'Schokoladenkuchen'
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
function getItems(db_url) {
|
|
|
|
|
db_url = "http://exodus.strfry.org:82/hq_needs/"
|
|
|
|
|
var db = new PouchDB(db_url)
|
|
|
|
|
//var db = require('pouchdb')(db_url)
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
db.allDocs({include_docs: true, key: 'Supermarkt'}
|
|
|
|
|
).then(docs => {
|
|
|
|
|
console.log(docs.rows[0].doc.items)
|
|
|
|
|
resolve(docs.rows[0].doc.items)
|
|
|
|
|
}).catch(reject)
|
|
|
|
|
})
|
|
|
|
|
var browserify = require('browserify')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const ServerLayout = {
|
|
|
|
|
view: vnode => [
|
|
|
|
|
m('!doctype[html]'),
|
|
|
|
|
m('head',
|
|
|
|
|
m('meta', {charset: 'utf-8'}),
|
|
|
|
|
),
|
|
|
|
|
m('body',
|
|
|
|
|
m('script', {src: "https://unpkg.com/mithril@1.1.6/mithril.min.js"}),
|
|
|
|
|
m('script', {src: "https://unpkg.com/polythene-mithril/dist/polythene-mithril-standalone.js"}),
|
|
|
|
|
m('script', {src: './bundle.js', defer: true}),
|
|
|
|
|
vnode.children
|
|
|
|
|
)]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const scripts = '<!DOCTYPE html>' +
|
|
|
|
|
'<script src="./bundle.js"></script>' +
|
|
|
|
|
'<script src="https://unpkg.com/mithril@1.1.6/mithril.min.js"></script>' +
|
|
|
|
|
'<script src="https://unpkg.com/polythene-mithril/dist/polythene-mithril-standalone.js"></script>' +
|
|
|
|
|
'<script></script>'
|
|
|
|
|
//const scripts = '<!DOCTYPE html>' +
|
|
|
|
|
// '<script src="./bundle.js" defer></script>' +
|
|
|
|
|
// '<script src="https://unpkg.com/mithril@1.1.6/mithril.min.js"></script>' +
|
|
|
|
|
// '<script></script>'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function render_index(req, res) {
|
|
|
|
|
getItems().then(items => {
|
|
|
|
|
console.log("the items i found: ", items)
|
|
|
|
|
var template = m(NeedsApp(), {items: items})
|
|
|
|
|
getModel().then(model => {
|
|
|
|
|
console.log("the items i found: ", model)
|
|
|
|
|
var template = m(ServerLayout, m(NeedsApp, { stores: model}))
|
|
|
|
|
render(template).then(function (html) {
|
|
|
|
|
res.writeHead(200, {'Content-Type': 'text/html'})
|
|
|
|
|
res.end(scripts + html)
|
|
|
|
|
res.end(html)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// do a render run for fun
|
|
|
|
|
getItems().then(db_docs => {
|
|
|
|
|
// var template = m(NeedsApp(), {items: db_docs})
|
|
|
|
|
// render(template).then(html => console.log(html))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
//import serve from 'serve-static'
|
|
|
|
|
var servejs = serve('.')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
polka()
|
|
|
|
|
.use(servejs)
|
|
|
|
|
.get('/', render_index)
|
|
|
|
|
.get('/bundle.js', (req, res) => {
|
|
|
|
|
var bundler = browserify({debug: true})
|
|
|
|
|
bundler.add('./client.js')
|
|
|
|
|
console.log('bundling the bundle...')
|
|
|
|
|
bundler.bundle().pipe(res);
|
|
|
|
|
// res.end()
|
|
|
|
|
}).get('/', render_index)
|
|
|
|
|
.listen(8000, err => {
|
|
|
|
|
if (err) throw err;
|
|
|
|
|
console.log(`> Running on localhost:8000`);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|