-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit 55b72a8
Showing
20 changed files
with
343 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
|
||
var express = require('express'); | ||
//var serveStatic = require('serve-static'); | ||
var path = require('path'); | ||
var favicon = require('serve-favicon'); | ||
var logger = require('morgan'); | ||
var cookieParser = require('cookie-parser'); | ||
var bodyParser = require('body-parser'); | ||
|
||
var routes = require('./routes/index'); | ||
var users = require('./routes/users'); | ||
var brands = require('./routes/brands'); | ||
|
||
var getBrand = function (req, res, next) { | ||
if ((req.params.brand == 'bb') || (req.params.brand == 'GENERIC') || (req.params.brand == 'matr') || (req.params.brand == 'fp')) | ||
{ | ||
req.brand = req.params.brand; | ||
next(); | ||
} | ||
else next(new Error('Brand Not Supported')); | ||
}; | ||
|
||
//var options = { | ||
// dotfiles: 'ignore', | ||
// etag: false, | ||
// extensions: ['htm', 'html', 'bin'], | ||
// index: false, | ||
// maxAge: '1d', | ||
// redirect: false, | ||
// setHeaders: function (res, path, stat) { | ||
// res.set('x-timestamp', Date.now()) | ||
// } | ||
//}; | ||
|
||
var app = express(); | ||
|
||
// view engine setup | ||
app.set('views', path.join(__dirname, 'views')); | ||
app.set('view engine', 'jade'); | ||
|
||
// uncomment after placing your favicon in /public | ||
//app.use(favicon(__dirname + '/public/favicon.ico')); | ||
app.use(logger('dev')); | ||
app.use(bodyParser.json()); | ||
app.use(bodyParser.urlencoded({ extended: false })); | ||
app.use(cookieParser()); | ||
app.use(express.static(path.join(__dirname, 'public'))); | ||
|
||
//app.use(express.static('public', options )); | ||
|
||
app.use('/', routes); | ||
app.use('/users', users); | ||
app.use('/:brand', [getBrand, brands]); | ||
|
||
// catch 404 and forward to error handler | ||
app.use(function(req, res, next) { | ||
var err = new Error('Not Found'); | ||
err.status = 404; | ||
next(err); | ||
}); | ||
|
||
// error handlers | ||
|
||
// development error handler | ||
// will print stacktrace | ||
if (app.get('env') === 'development') { | ||
app.use(function(err, req, res, next) { | ||
res.status(err.status || 500); | ||
res.render('error', { | ||
message: err.message, | ||
error: err | ||
}); | ||
}); | ||
} | ||
|
||
// production error handler | ||
// no stacktraces leaked to user | ||
app.use(function(err, req, res, next) { | ||
res.status(err.status || 500); | ||
res.render('error', { | ||
message: err.message, | ||
error: err | ||
}); | ||
}); | ||
|
||
|
||
module.exports = app; |
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,90 @@ | ||
#!/usr/bin/env node | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
var app = require('../app'); | ||
var debug = require('debug')('updateServer:server'); | ||
var http = require('http'); | ||
|
||
/** | ||
* Get port from environment and store in Express. | ||
*/ | ||
|
||
var port = normalizePort(process.env.PORT || '9080'); | ||
app.set('port', port); | ||
|
||
/** | ||
* Create HTTP server. | ||
*/ | ||
|
||
var server = http.createServer(app); | ||
|
||
/** | ||
* Listen on provided port, on all network interfaces. | ||
*/ | ||
|
||
server.listen(port); | ||
server.on('error', onError); | ||
server.on('listening', onListening); | ||
|
||
/** | ||
* Normalize a port into a number, string, or false. | ||
*/ | ||
|
||
function normalizePort(val) { | ||
var port = parseInt(val, 10); | ||
|
||
if (isNaN(port)) { | ||
// named pipe | ||
return val; | ||
} | ||
|
||
if (port >= 0) { | ||
// port number | ||
return port; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* Event listener for HTTP server "error" event. | ||
*/ | ||
|
||
function onError(error) { | ||
if (error.syscall !== 'listen') { | ||
throw error; | ||
} | ||
|
||
var bind = typeof port === 'string' | ||
? 'Pipe ' + port | ||
: 'Port ' + port | ||
|
||
// handle specific listen errors with friendly messages | ||
switch (error.code) { | ||
case 'EACCES': | ||
console.error(bind + ' requires elevated privileges'); | ||
process.exit(1); | ||
break; | ||
case 'EADDRINUSE': | ||
console.error(bind + ' is already in use'); | ||
process.exit(1); | ||
break; | ||
default: | ||
throw error; | ||
} | ||
} | ||
|
||
/** | ||
* Event listener for HTTP server "listening" event. | ||
*/ | ||
|
||
function onListening() { | ||
var addr = server.address(); | ||
var bind = typeof addr === 'string' | ||
? 'pipe ' + addr | ||
: 'port ' + addr.port; | ||
debug('Listening on ' + bind); | ||
} |
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,20 @@ | ||
{ | ||
"name": "updateServer", | ||
"version": "0.0.0", | ||
"private": true, | ||
"scripts": { | ||
"start": "node ./bin/www" | ||
}, | ||
"dependencies": { | ||
"body-parser": "~1.10.1", | ||
"cookie-parser": "~1.3.3", | ||
"debug": "~2.1.1", | ||
"express": "~4.11.0", | ||
"jade": "~1.9.0", | ||
"morgan": "~1.5.1", | ||
"serve-favicon": "~2.2.0", | ||
"serve-static": "~1", | ||
"express-hbs" : "~0", | ||
"multer" : "~0.1" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,6 @@ | ||
{ | ||
"sn" : "TR0000000244", | ||
"vMain" : 267, | ||
"vPos" : 1096, | ||
"posHash" : "9FD39D6B421CC488BD44076561446854C64E7672EC1672BEF3B8C03BC7066922" | ||
} |
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,6 @@ | ||
{ | ||
"sn" : "TR0000000244", | ||
"vMain" : 267, | ||
"vPos" : 1096, | ||
"posHash" : "9FD39D6B421CC488BD44076561446854C64E7672EC1672BEF3B8C03BC7066922" | ||
} |
Binary file not shown.
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 @@ | ||
sdfas |
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,10 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head lang="en"> | ||
<meta charset="UTF-8"> | ||
<title></title> | ||
</head> | ||
<body> | ||
<h1>BlaBla</h1> | ||
</body> | ||
</html> |
Binary file not shown.
Binary file not shown.
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 @@ | ||
BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3BB POS Version 3 |
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,8 @@ | ||
body { | ||
padding: 50px; | ||
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; | ||
} | ||
|
||
a { | ||
color: #00B7FF; | ||
} |
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,50 @@ | ||
/** | ||
* Created by vgene_000 on 2/17/2015. | ||
*/ | ||
var express = require('express'); | ||
var router = express.Router(); | ||
var fs = require('fs'); | ||
//var path = require('path'); | ||
|
||
router.param('type', function(req, res, next, type) { | ||
if ((type == 'main') || (type == 'pos')) | ||
{ | ||
req.fType = type; | ||
next(); | ||
} | ||
else { | ||
next(new Error('type not supported')); | ||
} | ||
}); | ||
|
||
router.get('/get-update/:type/:ver/:chunk.bin', function(req, res, next) { | ||
//pos.bb.1079.bin | ||
var pathfs = '../public/' + req.fType+'.'+req.brand+'.'+req.params.ver+'.bin'; | ||
var chunk = req.params.chunk; | ||
var chunkSize = 4096; | ||
//var sendBuf = new Buffer(chunkSize); | ||
|
||
fs.readFile(pathfs, function(err, file){ | ||
if (err) console.log(err); | ||
else | ||
{ | ||
var startFrom = chunk * chunkSize; | ||
// if (startFrom >= file.length) { | ||
// var err1 = new Error(); | ||
// err1.status = 404; | ||
// return next(err1); | ||
// } | ||
var endAt = startFrom + chunkSize; | ||
|
||
if (endAt >= file.length) | ||
{ | ||
endAt == file.length; | ||
res.append('Last-Chunk', 'true'); | ||
} | ||
var sendBuf = file.slice(startFrom, endAt); | ||
res.send(sendBuf); | ||
} | ||
}); | ||
}); | ||
|
||
module.exports = router; |
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,37 @@ | ||
//http://tsm-ip:9090/:brand/get-update/:type/:ver/:chunk.bin' | ||
|
||
var express = require('express'); | ||
var router = express.Router(); | ||
var fs = require('fs'); | ||
|
||
|
||
router.param('brand', function(req, res, next, brand) { | ||
req.brand = brand; | ||
next(req); | ||
}); | ||
|
||
/* | ||
*/ | ||
/* GET home page. */ | ||
router.get('/', function(req, res, next) { | ||
res.render('index', { title: 'Express' }); | ||
}); | ||
|
||
|
||
router.post('/get-ver', function (req, res) { | ||
var sn = req.body.sn; | ||
var vMain = req.body.vMain; | ||
var vPos= req.body.vPos; | ||
var brand = req.body.BB; | ||
var path = '../public/'+sn+'.json'; | ||
|
||
fs.readFile(path, 'utf8', function (err, file){ | ||
if (err) throw next(err); | ||
obj = JSON.parse(file); | ||
console.log(obj); | ||
res.send(obj.vMain+"\t"+obj.vPos+"\t"+obj.posHash); | ||
|
||
}); | ||
}); | ||
|
||
module.exports = router; |
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,9 @@ | ||
var express = require('express'); | ||
var router = express.Router(); | ||
|
||
/* GET users listing. */ | ||
router.get('/', function(req, res, next) { | ||
res.send('respond with a resource'); | ||
}); | ||
|
||
module.exports = router; |
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,6 @@ | ||
extends layout | ||
|
||
block content | ||
h1= message | ||
h2= error.status | ||
pre #{error.stack} |
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,5 @@ | ||
extends layout | ||
|
||
block content | ||
h1= title | ||
p Welcome to #{title} |
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,7 @@ | ||
doctype html | ||
html | ||
head | ||
title= title | ||
link(rel='stylesheet', href='/stylesheets/style.css') | ||
body | ||
block content |