Skip to content

Commit

Permalink
Get closer to a function UI development environment.
Browse files Browse the repository at this point in the history
  • Loading branch information
tecimovic committed Apr 16, 2021
1 parent 41bb14b commit 41c7598
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 22 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"test:unit:watchAll": "jest --watchAll",
"postinstall": "electron-builder install-app-deps && husky install",
"zap": "node src-script/zap-start.js --logToStdout --gen ./test/gen-template/zigbee/gen-templates.json",
"zap-devserver": "node src-script/zap-start.js server --allowCors --logToStdout --gen ./test/gen-template/zigbee/gen-templates.json",
"zap-server": "node src-script/zap-start.js server --logToStdout --gen ./test/gen-template/zigbee/gen-templates.json --reuseZapInstance",
"zap-status": "node src-script/zap-start.js status --reuseZapInstance",
"zaphelp": "node src-script/zap-start.js --help",
Expand Down
5 changes: 5 additions & 0 deletions quasar.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ module.exports = function (ctx) {
https: false,
port: 8080,
open: true, // opens browser window automatically
headers: {
// 'Access-Control-Allow-Methods': 'GET, POST, PUT, PATCH, DELETE, OPTIONS',
// 'Access-Control-Allow-Headers': 'Content-Type, Authorization',
'Access-Control-Allow-Origin': '*',
},
},

// animations: 'all', // --- includes all animations
Expand Down
2 changes: 2 additions & 0 deletions src-electron/main-process/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ async function startNormal(
.initHttpServer(ctx.db, argv.httpPort, argv.studioHttpPort, {
zcl: argv.zclProperties,
template: argv.generationTemplate,
allowCors: argv.allowCors,
})
.then(() => {
ipcServer.initServer(ctx.db, argv.httpPort)
Expand Down Expand Up @@ -357,6 +358,7 @@ async function startServer(argv, options = {}) {
.initHttpServer(ctx.db, argv.httpPort, argv.studioHttpPort, {
zcl: argv.zclProperties,
template: argv.generationTemplate,
allowCors: argv.allowCors,
})
.then(() => {
ipcServer.initServer(ctx.db, argv.httpPort)
Expand Down
14 changes: 12 additions & 2 deletions src-electron/server/http-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,23 @@ async function initHttpServer(
db,
port,
studioPort,
metafiles = {
options = {
allowCors: false,
zcl: env.builtinSilabsZclMetafile,
template: env.builtinTemplateMetafile,
}
) {
return new Promise((resolve, reject) => {
const app = express()

if (options.allowCors) {
env.logWarning('CORS is enabled. Please be careful.')
app.use(function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*')
next()
})
}

//app.use(express.urlencoded({ extended: true }))
app.use(express.json())
app.use(
Expand All @@ -122,7 +132,7 @@ async function initHttpServer(
})
)

app.use(userSessionHandler(db, metafiles))
app.use(userSessionHandler(db, options))

// REST modules
registerAllRestModules(db, app)
Expand Down
7 changes: 6 additions & 1 deletion src-electron/util/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,12 @@ function processCommandLineArguments(argv) {
.option('watchdogTimer', {
desc: `In a server mode, how long of no-activity (in ms) shuts down the server.`,
type: 'number',
default: 60000,
default: 600000, // 10 minutes
})
.option('allowCors', {
desc: `Sets the CORS policy to be enabled or disabled.`,
type: 'boolean',
default: false,
})
.usage('Usage: $0 <command> [options] ... [file.zap] ...')
.version(
Expand Down
30 changes: 16 additions & 14 deletions src-script/zap-start.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,25 @@ const scriptUtil = require('./script-util.js')
//workaround: executeCmd()/spawn() fails silently without complaining about missing path to electron
process.env.PATH = process.env.PATH + ':/usr/local/bin/'
let startTime = process.hrtime()
let args = process.argv.slice(2)
let executor = null
if (
args[0] == 'generate' ||
args[0] == 'selfCheck' ||
args[0] == 'analyze' ||
args[0] == 'convert' ||
args[0] == 'server'
)
executor = 'node'
else executor = 'electron'

scriptUtil
.stampVersion()
.then(() => scriptUtil.rebuildSpaIfNeeded())
.then((ctx) => {
.then(() => {
if (executor === 'electron') return scriptUtil.rebuildSpaIfNeeded()
})
.then(() => {
let cmdArgs = ['src-electron/main-process/electron-main.js']
args = process.argv.slice(2)
let executor = null
if (
args[0] == 'generate' ||
args[0] == 'selfCheck' ||
args[0] == 'analyze' ||
args[0] == 'convert' ||
args[0] == 'server'
)
executor = 'node'
else executor = 'electron'

if (executor === 'electron' && process.platform == 'linux') {
if (!process.env.DISPLAY) {
Expand All @@ -48,7 +50,7 @@ scriptUtil
}
}
cmdArgs.push(...args)
return scriptUtil.executeCmd(ctx, executor, cmdArgs)
return scriptUtil.executeCmd(null, executor, cmdArgs)
})
.then(() => {
let endTime = process.hrtime(startTime)
Expand Down
20 changes: 15 additions & 5 deletions src/boot/axios.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ if (window.sessionStorage.getItem('session_uuid') == null) {
window.sessionStorage.setItem('session_uuid', uuidv4())
}

/**
* URL rewriter that can come handy in development mode.
*
* @param {*} url
* @returns
*/
function fillUrl(url) {
return url
}

/**
* Internal function that processes response from the server for any request.
*
Expand Down Expand Up @@ -82,7 +92,7 @@ function fillConfig(config) {
*/
function serverGet(url, config = null) {
if (log) console.log(`GET → : ${url}, ${config}`)
return axios['get'](url, fillConfig(config))
return axios['get'](fillUrl(url), fillConfig(config))
.then((response) => processResponse('GET', url, response))
.catch((error) => console.log(error))
}
Expand All @@ -95,7 +105,7 @@ function serverGet(url, config = null) {
*/
function serverDelete(url, config = null) {
if (log) console.log(`DELETE → : ${url}, ${config}`)
return axios['delete'](url, fillConfig(config))
return axios['delete'](fillUrl(url), fillConfig(config))
.then((response) => processResponse('DELETE', url, response))
.catch((error) => console.log(error))
}
Expand All @@ -114,7 +124,7 @@ function serverDelete(url, config = null) {
*/
function serverPost(url, data, config = null) {
if (log) console.log(`POST → : ${url}, ${data}`)
return axios['post'](url, data, fillConfig(config))
return axios['post'](fillUrl(url), data, fillConfig(config))
.then((response) => processResponse('POST', url, response))
.catch((error) => console.log(error))
}
Expand All @@ -132,7 +142,7 @@ function serverPost(url, data, config = null) {
*/
function serverPut(url, data, config = null) {
if (log) console.log(`PUT → : ${url}, ${data}`)
return axios['put'](url, data, fillConfig(config))
return axios['put'](fillUrl(url), data, fillConfig(config))
.then((response) => processResponse('PUT', url, response))
.catch((error) => console.log(error))
}
Expand All @@ -145,7 +155,7 @@ function serverPut(url, data, config = null) {
*/
function serverPatch(url, data, config = null) {
if (log) console.log(`PATCH → : ${url}, ${data}`)
return axios['patch'](url, data, fillConfig(config))
return axios['patch'](fillUrl(url), data, fillConfig(config))
.then((response) => processResponse('PATCH', url, response))
.catch((error) => console.log(error))
}
Expand Down

0 comments on commit 41c7598

Please sign in to comment.