Skip to content
This repository was archived by the owner on Aug 5, 2024. It is now read-only.

Commit 1c5e561

Browse files
committed
codesandbox magic
1 parent 0ae88c5 commit 1c5e561

File tree

3 files changed

+34
-15
lines changed

3 files changed

+34
-15
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,7 @@ The gateway can be run locally (no cloud dependencies), in GitHub CodeSpaces or
1010
| :exclamation: This implementation is for prototyping only and not meant for production. |
1111
| --------------------------------------------------------------------------------------- |
1212

13-
## Local development / GitHub Codespaces
14-
15-
Running the gateway in GitHub codespaces will give you an addressable web server that will be reachable by devices which the codespace
16-
is active. It is an easy to get a development gateway available on the web without having to deal with network issues.
17-
The tools will automatically detect CodeSpaces and self configure.
18-
19-
Make sure to follow the provisioning steps in the documentation before trying to run locally.
13+
## Local development
2014

2115
- setup Node.JS 18
2216

@@ -54,6 +48,12 @@ You can also access the Swagger sandbox locally:
5448
- Click Authorize
5549
- Use user/password `devstoreaccount1:Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==`
5650

51+
### GitHub CodeSpaces, CodeSandbox.io
52+
53+
Running the gateway in GitHub Codespaces/CodeSandbox will give you an addressable web server that will be reachable by devices which the codespace
54+
is active. It is an easy to get a development gateway available on the web without having to deal with network issues.
55+
The tools will automatically detect CodeSpaces/CodeSandbox and self configure.
56+
5757
## Azure services
5858

5959
Make sure to follow the provisioning steps in the documentation before trying to run locally.

dev.mjs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,28 @@ const out = dotenv.config({ path: azure ? "./.env" : "./local.env" })
88
if (out.error) throw out.error
99

1010
const port = process.env.PORT || (process.env.PORT = "7071")
11-
// codespace special handling
12-
const { CODESPACE_NAME, GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN } = process.env
11+
const {
12+
CODESPACE_NAME,
13+
GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN,
14+
CODESANDBOX_HOST,
15+
} = process.env
16+
// GitHub codespaces
1317
if (CODESPACE_NAME && GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN) {
1418
process.env.WEBSITE_HOSTNAME = `${CODESPACE_NAME}-${port}.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}`
1519
process.env.WEBSITE_PROTOCOL = "https"
16-
console.log(`GitHub Codespace environment detected...`)
17-
console.warn(`- make sure to change the visibility of port '${port}' to 'Public'`)
18-
} else if (!azure) {
20+
console.log(`GitHub Codespace detected...`)
21+
console.warn(
22+
`- make sure to change the visibility of port '${port}' to 'Public'`
23+
)
24+
}
25+
// Codesandbox
26+
else if (CODESANDBOX_HOST) {
27+
process.env.WEBSITE_HOSTNAME = CODESANDBOX_HOST
28+
process.env.WEBSITE_PROTOCOL = "https"
29+
console.log(`Codesandbox.io detected...`)
30+
}
31+
// local dev
32+
else if (!azure) {
1933
const address = (() => {
2034
const nis = networkInterfaces()
2135
for (const interfaceName in nis) {

src/util.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@ import { DeviceInfo } from "./schema"
66
*/
77
export function selfUrl() {
88
// use https://learn.microsoft.com/en-us/azure/app-service/reference-app-settings?tabs=kudu%2Cdotnet
9-
const hostname = process.env["WEBSITE_HOSTNAME"]
9+
const hostname = process.env.WEBSITE_HOSTNAME
1010
if (!hostname) throw new Error("WEBSITE_HOSTNAME not configured")
11-
const protocol = /^(127\.|0\.|localhost)/i.test(hostname) ? "http" : "https"
12-
return `${protocol}://${hostname}`
11+
const protocol =
12+
process.env.WEBSITE_PROTOCOL || /^(127\.|0\.|localhost)/i.test(hostname)
13+
? "http"
14+
: "https"
15+
const url = `${protocol}://${hostname}`
16+
console.log({ url })
17+
return url
1318
}
1419

1520
export function selfHost() {

0 commit comments

Comments
 (0)