begin migrating parsing to backend
This commit is contained in:
parent
e1e17d2313
commit
cc9e1b86e6
3 changed files with 27 additions and 13 deletions
|
@ -33,8 +33,8 @@ ws281x.configure({
|
|||
});
|
||||
|
||||
export function set_pattern(pat) {
|
||||
pattern = pat
|
||||
log.debug("pattern set");
|
||||
pattern = pat;
|
||||
}
|
||||
|
||||
export const functions = {
|
||||
|
|
5
parse.js
Normal file
5
parse.js
Normal file
|
@ -0,0 +1,5 @@
|
|||
export default function parse(data) {
|
||||
return {
|
||||
errors: ["not yet implemented"]
|
||||
}
|
||||
}
|
31
server.js
31
server.js
|
@ -1,7 +1,7 @@
|
|||
import * as net from 'net';
|
||||
import * as fs from 'fs';
|
||||
import { functions, reqs } from './lights.js'
|
||||
import Logger, { levels } from './logger.js';
|
||||
import parse from './parse.js'
|
||||
|
||||
const cfg = JSON.parse(fs.readFileSync('./config.json'));
|
||||
const log = new Logger("server", cfg.log_level ? levels[cfg.log_level] : levels.INFO);
|
||||
|
@ -16,18 +16,27 @@ export function recv(callback, errorCallback) {
|
|||
server.on('connection', (con) => {
|
||||
console.log('connection recieved: ' +
|
||||
con.remoteAddress + ":" + con.remotePort);
|
||||
let data = [];
|
||||
for (let key of Object.keys(functions)) {
|
||||
data.push({
|
||||
n: key.toUpperCase(),
|
||||
a: reqs[key.toLowerCase()] != undefined ? reqs[key.toLowerCase()] : true
|
||||
});
|
||||
}
|
||||
let functions_str = JSON.stringify(data);
|
||||
con.write(functions_str);
|
||||
log.debug(`sending ${functions_str}`);
|
||||
// let data = [];
|
||||
// for (let key of Object.keys(functions)) {
|
||||
// data.push({
|
||||
// n: key.toUpperCase(),
|
||||
// a: reqs[key.toLowerCase()] != undefined ? reqs[key.toLowerCase()] : true
|
||||
// });
|
||||
// }
|
||||
// let functions_str = JSON.stringify(data);
|
||||
// con.write(functions_str);
|
||||
// log.debug(`sending ${functions_str}`);
|
||||
con.on('data', (data) => {
|
||||
let parsed_data = parse(data);
|
||||
|
||||
if (parsed_data.errors) {
|
||||
con.write(JSON.stringify(parsed_data.errors));
|
||||
errorCallback(parsed_data);
|
||||
}
|
||||
else {
|
||||
con.write("success");
|
||||
callback(data);
|
||||
}
|
||||
});
|
||||
con.on('close', () => {
|
||||
console.log('recieved close for ' +
|
||||
|
|
Loading…
Reference in a new issue