Convert initial server code to intval3 basic structure

This commit is contained in:
mmcwilliams 2017-08-21 22:59:44 -04:00
parent ccb62296a5
commit 6716be882b
1 changed files with 43 additions and 20 deletions

View File

@ -3,16 +3,18 @@
const ble = require('./lib/blootstrap') const ble = require('./lib/blootstrap')
const restify = require('restify') const restify = require('restify')
const logger = require('winston') const logger = require('winston')
const gpio = require('gpio') const gpio = require('gpio')
const fs = require('fs')
const pin = {} const pin = {}
const PACKAGE = require('./package.json')
const PORT = process.env.PORT || 6699 const PORT = process.env.PORT || 6699
const APPNAME = 'intval3' const APPNAME = PACKAGE.name
const INDEX = fs.readFileSync('./app/www/index.html', 'utf8')
let app = restify.createServer({ let app = restify.createServer({
name: APPNAME, name: APPNAME,
version: '1.0.0' version: '0.0.1'
}) })
function createPins () { function createPins () {
@ -20,32 +22,53 @@ function createPins () {
direction: 'out', direction: 'out',
interval: 100, interval: 100,
ready : () => { ready : () => {
logger.info(`Set pin 4 to OUTPUT`)
} }
}) })
} }
function Frame (dir = true, length = 0, delay = 0) { function createServer () {
app.get('/', index)
//app.all('/frame', rFrame)
app.get('/status', status)
app.listen(PORT, () => {
console.log(`${APPNAME} listening on port ${PORT}!`)
})
}
function rFrame (req, res, next) {
res.send({})
return next()
}
function frame (dir = true, length = 0, delay = 0) {
}
function rStatus (req, res, next) {
const obj = status()
res.send(obj)
return next()
}
function status () {
const obj = {}
return obj
} }
function index (req, res, next) { function index (req, res, next) {
res.send( res.end(INDEX)
`<h1>Welcome to my app!</h1> return next()
<form action="/blink" method="post">
<input type="submit" value="Blink!" />
</form>`)
next()
} }
ble.on('data', (str) => {
function init () {
createPins()
createServer()
ble.on('data', (str) => {
console.log(str) console.log(str)
blink() })
}) }
app.get('/', index) init()
app.all('/blink', blink)
app.listen(PORT, () => {
console.log(`${APPNAME} listening on port ${PORT}!`)
})