mirror of
https://github.com/fazo96/ipfs-boards
synced 2025-01-25 14:54:19 +01:00
updated code
This commit is contained in:
parent
e3bc70df94
commit
d4fc72d42f
43
lib/boards-api-http.js
Normal file
43
lib/boards-api-http.js
Normal file
@ -0,0 +1,43 @@
|
||||
// HTTP bindings for boards-api
|
||||
|
||||
var express = require('express')
|
||||
var app = express()
|
||||
|
||||
// Generates a callback function to pass the API response to HTTP
|
||||
var apiToHandler = function(request,response){
|
||||
return (function(a,b){
|
||||
var req = a
|
||||
var res = b
|
||||
return function(err,r){
|
||||
if(err){
|
||||
res.status(500)
|
||||
res.send(err)
|
||||
} else {
|
||||
if(r.split){
|
||||
res.send(r)
|
||||
} else {
|
||||
res.json(r)
|
||||
}
|
||||
}
|
||||
}
|
||||
})(request,response)
|
||||
}
|
||||
|
||||
module.exports = function(boards,options){
|
||||
options = options || {}
|
||||
|
||||
// Serve web app
|
||||
app.use(express.static(__dirname+'/../webapp'))
|
||||
|
||||
app.get('/@:user',(req,res) => {
|
||||
boards.getProfile(req.params.user,apiToHandler(req,res))
|
||||
})
|
||||
|
||||
app.get('/@:user/:board',(req,res) => {
|
||||
boards.getBoardSettings(req.params.user,req.params.board,apiToHandler(req,res))
|
||||
})
|
||||
|
||||
app.listen(options.port || 3000,function(){
|
||||
console.log('Started Web Server')
|
||||
})
|
||||
}
|
1
lib/boards-api-webrtc.js
Normal file
1
lib/boards-api-webrtc.js
Normal file
@ -0,0 +1 @@
|
||||
// WebSockets wrapper for boards-api
|
@ -2,60 +2,17 @@
|
||||
|
||||
var ipfs = require('ipfs-api')('localhost','5001')
|
||||
var BoardsAPI = require('../lib/boards-api.js')
|
||||
var express = require('express')
|
||||
var app = express()
|
||||
var BoardsAPIHttp = require('../lib/boards-api-http.js')
|
||||
|
||||
var boards = new BoardsAPI(ipfs)
|
||||
|
||||
// Serve web app
|
||||
app.use(express.static('../webapp'))
|
||||
|
||||
// Generates a callback function to pass the API response to HTTP
|
||||
var apiToHandler = function(request,response){
|
||||
return (function(a,b){
|
||||
var req = a
|
||||
var res = b
|
||||
return function(err,r){
|
||||
if(err){
|
||||
res.status(500)
|
||||
res.send(err)
|
||||
} else {
|
||||
if(r.split){
|
||||
res.send(r)
|
||||
} else {
|
||||
res.json(r)
|
||||
}
|
||||
}
|
||||
}
|
||||
})(request,response)
|
||||
}
|
||||
|
||||
// Create gateways to access the BoardsAPI
|
||||
|
||||
app.get('/@:user',(req,res) => {
|
||||
boards.getProfile(req.params.user,apiToHandler(req,res))
|
||||
})
|
||||
|
||||
app.get('/@:user/:board',(req,res) => {
|
||||
boards.getBoardSettings(req.params.user,req.params.board,apiToHandler(req,res))
|
||||
})
|
||||
|
||||
setInterval(boards.searchUsers.bind(boards),3 * 60 * 1000)
|
||||
boards.searchUsers()
|
||||
|
||||
// Start the web server
|
||||
|
||||
function startWebServer(){
|
||||
// Start http server
|
||||
app.listen(3000,function(){
|
||||
console.log('Started Web Server')
|
||||
})
|
||||
}
|
||||
var server
|
||||
|
||||
boards.init(function(err){
|
||||
if(err){
|
||||
console.log(err)
|
||||
} else {
|
||||
startWebServer()
|
||||
server = BoardsAPIHttp(boards)
|
||||
setInterval(boards.searchUsers.bind(boards),3 * 60 * 1000)
|
||||
boards.searchUsers()
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user