-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e3b3a54
commit bcc8d9e
Showing
10 changed files
with
183 additions
and
13 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
"use strict"; | ||
const express = require('express'); | ||
const EventEmitter = require('events'); | ||
|
||
class RestFul extends EventEmitter { | ||
constructor(config) { | ||
super(); | ||
this.restFulPort = config.port; | ||
this.restFulDebug = config.debug; | ||
|
||
this.restFulData = { | ||
info: 'This data is not available at this time.', | ||
state: 'This data is not available at this time.' | ||
}; | ||
|
||
this.connect(); | ||
}; | ||
|
||
connect() { | ||
try { | ||
const restFul = express(); | ||
restFul.set('json spaces', 2); | ||
restFul.get('/info', (req, res) => { res.json(this.restFulData.info) }); | ||
restFul.get('/state', (req, res) => { res.json(this.restFulData.state) }); | ||
|
||
restFul.listen(this.restFulPort, () => { | ||
this.emit('connected', `RESTful started on port: ${this.restFulPort}`) | ||
}); | ||
|
||
} catch (error) { | ||
this.emit('error', `RESTful error: ${error}`) | ||
} | ||
}; | ||
|
||
update(path, data) { | ||
switch (path) { | ||
case 'info': | ||
this.restFulData.info = data; | ||
break; | ||
case 'state': | ||
this.restFulData.state = data; | ||
break; | ||
default: | ||
break; | ||
}; | ||
const emitDebug = this.restFulDebug ? this.emit('debug', `RESTFul update path: ${path}, data: ${data}`) : false; | ||
}; | ||
}; | ||
module.exports = RestFul; |