-
Notifications
You must be signed in to change notification settings - Fork 0
/
ServerDemo.js
42 lines (35 loc) · 1.4 KB
/
ServerDemo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const express = require('express')
const phoneStashLib = require('./index.js')
phoneStashLib.PhoneStashLoadPhoneTemplate();
const app = express()
const port = 3000
const fs = require('fs');
const dummyDB = JSON.parse(fs.readFileSync(__dirname+ '/Database.json', 'utf8'));
app.use(express.static('Phone_configs'))
app.get('*', (req, res) =>{
console.log(req.url)
let mac = phoneStashLib.PhoneStashMacParser(req.url)
console.log(mac)
let phoneConf =LoadPhoneConfbyMacFromDB(mac)
let phoneStash
let TemplateName = ''
let MyCode = ''
if(phoneConf){
phoneStash = new phoneStashLib.phoneStash(phoneConf)
phoneStash.Headers = req.headers
let MyTarget = phoneStashLib.PhoneStashDirectoryParser(req.url)
if(MyTarget && MyTarget!='') {
console.log(phoneConf.PhoneTemplateName + " " + phoneConf.MainTemplateName + " directory: " + MyTarget)
TemplateName = MyTarget
}
let configBody = phoneStash.ReanderConfig()
if(req.url.indexOf('Debug=True')>-1){
configBody = '<b>Debug Mode</b><br/>'+req.url +'<br/>mac:'+ mac +'<br/>TemplateName:'+phoneStash.TemplateName+ '<br/>'+JSON.stringify(phoneStash)+'<br/>configBody:<br/>'+configBody
}
res.send(configBody)
}
})
app.listen(port, () => console.log(`PhoneStash WebServer Demo listening on port ${port}!`))
function LoadPhoneConfbyMacFromDB(mac) {
return dummyDB[mac]
}