GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — :wrench: wait for server ping · nullstack/nullstack@5efe0ff

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • scripts
    • index.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎scripts/index.js‎

Copy file name to clipboardExpand all lines: scripts/index.js
+20-3Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const { existsSync } = require('fs');
88
const customConfig = path.resolve(process.cwd(), './webpack.config.js');
99
const config = existsSync(customConfig) ? require(customConfig) : require('../webpack.config');
1010
const dotenv = require('dotenv')
11+
const fetch = require('node-fetch')
1112

1213
function getConfig(options) {
1314
return config.map((env) => env(null, options))
@@ -62,6 +63,7 @@ async function start({ input, port, env, mode = 'spa', hot }) {
6263
process.env['NULLSTACK_ENVIRONMENT_HOT'] = (!!hot).toString()
6364
if (!process.env['NULLSTACK_PROJECT_DOMAIN']) process.env['NULLSTACK_PROJECT_DOMAIN'] = 'localhost'
6465
if (!process.env['NULLSTACK_WORKER_PROTOCOL']) process.env['NULLSTACK_WORKER_PROTOCOL'] = 'http'
66+
const target = `${process.env['NULLSTACK_WORKER_PROTOCOL']}://${process.env['NULLSTACK_PROJECT_DOMAIN']}:${process.env['NULSTACK_SERVER_PORT_YOU_SHOULD_NOT_CARE_ABOUT']}`
6567
const devServerOptions = {
6668
hot: 'only',
6769
open: false,
@@ -80,23 +82,38 @@ async function start({ input, port, env, mode = 'spa', hot }) {
8082
},
8183
proxy: {
8284
context: () => true,
83-
target: `${process.env['NULLSTACK_WORKER_PROTOCOL']}://${process.env['NULLSTACK_PROJECT_DOMAIN']}:${process.env['NULSTACK_SERVER_PORT_YOU_SHOULD_NOT_CARE_ABOUT']}`,
85+
target,
8486
proxyTimeout: 10 * 60 * 1000,
8587
timeout: 10 * 60 * 1000,
8688
},
8789
setupMiddlewares: (middlewares, devServer) => {
8890
if (!devServer) {
8991
throw new Error('webpack-dev-server is not defined');
9092
}
91-
middlewares.unshift((req, res, next) => {
93+
middlewares.unshift(async (req, res, next) => {
9294
if (req.originalUrl.indexOf('.hot-update.') === -1) {
9395
if (req.originalUrl.startsWith('/nullstack/')) {
9496
console.log(` ⚙️ [${req.method}] ${req.originalUrl}`)
9597
} else {
9698
console.log(` 🕸️ [${req.method}] ${req.originalUrl}`)
9799
}
98100
}
99-
next()
101+
async function waitForServer() {
102+
if (req.originalUrl.includes('.')) {
103+
return next()
104+
}
105+
try {
106+
await fetch(`${target}${req.originalUrl}`)
107+
next()
108+
} catch (error) {
109+
if (error.message.includes('ECONNREFUSED')) {
110+
setTimeout(waitForServer, 100)
111+
} else {
112+
throw error
113+
}
114+
}
115+
}
116+
waitForServer()
100117
});
101118
return middlewares;
102119
},

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.