Merge pull request #1083 from Budibase/bug/4001-to-0-fix

Attempting to fix the 4001 bug - using ephemeral ports in production (builder)
This commit is contained in:
Martin McKeaveney 2021-02-22 13:57:26 +00:00 committed by GitHub
commit f16ec615aa
17 changed files with 53 additions and 38 deletions

View File

@ -1,5 +1,8 @@
{
"baseUrl": "http://localhost:4001/_builder/",
"baseUrl": "http://localhost:4005/_builder/",
"video": true,
"projectId": "bmbemn"
"projectId": "bmbemn",
"env": {
"PORT": "4005"
}
}

View File

@ -2,7 +2,7 @@ context('Create an Application', () => {
beforeEach(() => {
cy.server()
cy.visit('localhost:4001/_builder')
cy.visit(`localhost:${Cypress.env("PORT")}/_builder`)
})
// https://on.cypress.io/interacting-with-elements
@ -11,7 +11,7 @@ context('Create an Application', () => {
// https://on.cypress.io/type
cy.createApp('My Cool App', 'This is a description')
cy.visit('localhost:4001/_builder')
cy.visit(`localhost:${Cypress.env("PORT")}/_builder`)
cy.contains('My Cool App').should('exist')
})

View File

@ -1,7 +1,7 @@
context("Create a automation", () => {
before(() => {
cy.server()
cy.visit("localhost:4001/_builder")
cy.visit(`localhost:${Cypress.env("PORT")}/_builder`)
cy.createApp(
"Automation Test App",

View File

@ -1,6 +1,6 @@
xcontext('Create a Binding', () => {
before(() => {
cy.visit('localhost:4001/_builder')
cy.visit(`localhost:${Cypress.env("PORT")}/_builder`)
cy.createApp('Binding App', 'Binding App Description')
cy.navigateToFrontend()
})

View File

@ -1,7 +1,7 @@
xcontext("Create Components", () => {
before(() => {
cy.server()
cy.visit("localhost:4001/_builder")
cy.visit(`localhost:${Cypress.env("PORT")}/_builder`)
// https://on.cypress.io/type
cy.createApp("Table App", "Table App Description")
cy.createTable("dog", "name", "age")

View File

@ -1,6 +1,6 @@
context("Create a Table", () => {
before(() => {
cy.visit("localhost:4001/_builder")
cy.visit(`localhost:${Cypress.env("PORT")}/_builder`)
cy.createApp("Table App", "Table App Description")
})

View File

@ -2,7 +2,7 @@ context('Create a User', () => {
before(() => {
cy.server()
cy.visit('localhost:4001/_builder')
cy.visit(`localhost:${Cypress.env("PORT")}/_builder`)
// https://on.cypress.io/type
cy.createApp('User App', 'This app is used to test user creation')
})

View File

@ -1,6 +1,6 @@
context("Create a View", () => {
before(() => {
cy.visit("localhost:4001/_builder")
cy.visit(`localhost:${Cypress.env("PORT")}/_builder`)
cy.createApp("View App", "View App Description")
cy.createTable("data")
cy.addColumn("data", "group", "Text")

View File

@ -2,7 +2,7 @@
context('Screen Tests', () => {
before(() => {
cy.server()
cy.visit('localhost:4001/_builder')
cy.visit(`localhost:${Cypress.env("PORT")}/_builder`)
cy.createApp('Conor Cy App', 'Table App Description')
cy.navigateToFrontend()
})

View File

@ -7,6 +7,7 @@ const rimraf = require("rimraf")
const { join, resolve } = require("path")
// const run = require("../../cli/src/commands/run/runHandler")
const initialiseBudibase = require("../../server/src/utilities/initialiseBudibase")
const cypressConfig = require("../cypress.json")
const homedir = join(require("os").homedir(), ".budibase")
@ -15,6 +16,7 @@ rimraf.sync(homedir)
process.env.BUDIBASE_API_KEY = "6BE826CB-6B30-4AEC-8777-2E90464633DE"
process.env.NODE_ENV = "cypress"
process.env.ENABLE_ANALYTICS = "false"
process.env.PORT = cypressConfig.env.PORT
// Stop info logs polluting test outputs
process.env.LOG_LEVEL = "error"

View File

@ -14,8 +14,8 @@
"cy:run": "cypress run",
"cy:open": "cypress open",
"cy:run:ci": "cypress run --browser electron --record --key f308590b-6070-41af-b970-794a3823d451",
"cy:test": "start-server-and-test cy:setup http://localhost:4001/_builder cy:run",
"cy:ci": "start-server-and-test cy:setup http://localhost:4001/_builder cy:run:ci"
"cy:test": "start-server-and-test cy:setup http://localhost:4005/_builder cy:run",
"cy:ci": "start-server-and-test cy:setup http://localhost:4005/_builder cy:run:ci"
},
"jest": {
"globals": {

View File

@ -13,7 +13,8 @@
if (production) {
return `${appUrl}/${uri}`
} else {
return `http://localhost:4001/${uri}`
return `${window.location.origin}/${uri}`
}
}

View File

@ -8,9 +8,6 @@ CLIENT_ID={{clientId}}
# used to create cookie hashes
JWT_SECRET={{cookieKey1}}
# port to run http server on
PORT=4001
# error level for koa-pino
LOG_LEVEL=info

View File

@ -36,7 +36,7 @@
"test:integration": "jest routes --runInBand",
"test:watch": "jest --watch",
"run:docker": "node src/index",
"dev:builder": "nodemon src/index.js",
"dev:builder": "PORT=4001 nodemon src/index.js",
"electron": "electron src/electron.js",
"build:electron": "electron-builder --dir",
"publish:electron": "electron-builder -mwl --publish always",

View File

@ -50,8 +50,10 @@ destroyable(server)
server.on("close", () => console.log("Server Closed"))
module.exports = server.listen(env.PORT || 4001, async () => {
module.exports = server.listen(env.PORT || 0, async () => {
console.log(`Budibase running on ${JSON.stringify(server.address())}`)
env._set("PORT", server.address().port)
eventEmitter.emitPort(env.PORT)
automations.init()
// only init the self hosting DB info in the Pouch, not needed in self hosting prod
if (!env.CLOUD) {

View File

@ -7,6 +7,7 @@ const { existsSync } = require("fs-extra")
const initialiseBudibase = require("./utilities/initialiseBudibase")
const { budibaseAppsDir } = require("./utilities/budibaseDir")
const { openNewGitHubIssue, debugInfo } = require("electron-util")
const eventEmitter = require("./events")
const budibaseDir = budibaseAppsDir()
const envFile = join(budibaseDir, ".env")
@ -17,7 +18,11 @@ async function startApp() {
}
// evict environment from cache, so it reloads when next asked
delete require.cache[require.resolve("./environment")]
// store the port incase its going to get overridden
const port = process.env.PORT
require("dotenv").config({ path: envFile })
// overwrite the port - don't want to use dotenv for the port
require("./environment")._set("PORT", port)
unhandled({
showDialog: true,
@ -34,9 +39,6 @@ async function startApp() {
},
})
const APP_URL = "http://localhost:4001/_builder"
const APP_TITLE = "Budibase Builder"
let win
function handleRedirect(e, url) {
@ -46,6 +48,9 @@ async function startApp() {
async function createWindow() {
app.server = require("./app")
eventEmitter.on("internal:port", port => {
const APP_URL = `http://localhost:${port}/_builder`
const APP_TITLE = "Budibase Builder"
win = new BrowserWindow({
width: 1920,
height: 1080,
@ -62,6 +67,7 @@ async function startApp() {
// open _blank in default browser
win.webContents.on("new-window", handleRedirect)
win.webContents.on("will-navigate", handleRedirect)
})
}
app.whenReady().then(createWindow)

View File

@ -19,6 +19,10 @@ class BudibaseEmitter extends EventEmitter {
emitTable(eventName, appId, table = null) {
tableEmission({ emitter: this, eventName, appId, table })
}
emitPort(portNumber) {
this.emit("internal:port", portNumber)
}
}
const emitter = new BudibaseEmitter()