Last active
March 2, 2016 14:45
-
-
Save AlexFrazer/951163178e924c2eb7e1 to your computer and use it in GitHub Desktop.
Here you can publish from a search page one at a time.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
import knex from 'knex'; | |
import express from 'express'; | |
import socket from 'socket.io'; | |
import bodyParser from 'body-parser'; | |
export const app = express(); | |
export const db = knex({ client: 'pg', /** your config here */ }); | |
app.use((req, res, next) => { | |
req.db = db; | |
next(); | |
}); | |
export const server = http.createServer(app).listen(8124); | |
export const io = socket.listen(server); | |
// some boilerplate code here | |
// now you can use a route like this | |
app.route('/products', async function (req, res, next) { | |
const search = req.db('products').select('*').where(req.queryParams).stream(); | |
search.on('data', d => io.emit('result', d)); | |
search.on('end', res.end.bind(res)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment