generated from tailored/router-template
	add check port and change process
This commit is contained in:
		| @@ -11,7 +11,7 @@ app | ||||
|   .addTo(app); | ||||
|  | ||||
| console.log('httpsConfig', `https://localhost:51015/client/router?path=demo`); | ||||
| app.listen(51015, () => { | ||||
| app.listen(51016, () => { | ||||
|   console.log('Router App is running on https://localhost:51015'); | ||||
| }); | ||||
|  | ||||
|   | ||||
							
								
								
									
										26
									
								
								src/main.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								src/main.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,26 @@ | ||||
| import { app } from './index.ts'; | ||||
| import { proxyRoute } from './proxy-route/index.ts'; | ||||
| import getPort, { portNumbers } from 'get-port'; | ||||
| console.log('httpsConfig', `https://localhost:51015/client/router?path=demo`); | ||||
| // 检车端口可用性 | ||||
| const isPortAvailable = await getPort({ port: portNumbers(51015, 52000) }); | ||||
| if (!isPortAvailable) { | ||||
|   console.log(`Port ${isPortAvailable} is not available`); | ||||
|   process.exit(1); | ||||
| } | ||||
|  | ||||
| app.listen(isPortAvailable, () => { | ||||
|   console.log('Router App is running on https://localhost:51015'); | ||||
| }); | ||||
|  | ||||
| app.server.on(proxyRoute); | ||||
|  | ||||
| // 如果是被fork启动的,向父进程发送消息 | ||||
| if (process.env.NODE_ENV_PARENT === 'fork') { | ||||
|   process.send({ | ||||
|     type: 'fork', | ||||
|     data: { | ||||
|       port: isPortAvailable, | ||||
|     }, | ||||
|   }); | ||||
| } | ||||
| @@ -118,7 +118,20 @@ export const installApp = async (app: Package) => { | ||||
|     }; | ||||
|   } | ||||
| }; | ||||
|  | ||||
| export const addCacheAssistantConfig = (config: any) => { | ||||
|   const cacheAssistantConfig = getCacheAssistantConfig(); | ||||
|   let proxy = cacheAssistantConfig.proxy || []; | ||||
|   const index = proxy.findIndex((item: any) => item.user === config.user && item.key === config.key); | ||||
|   if (index !== -1) { | ||||
|     proxy[index] = config; | ||||
|   } else { | ||||
|     proxy.push(config); | ||||
|   } | ||||
|   setConfig({ | ||||
|     ...cacheAssistantConfig, | ||||
|     proxy, | ||||
|   }); | ||||
| }; | ||||
| export const uninstallApp = async (app: Package) => { | ||||
|   try { | ||||
|     const { user, key } = app; | ||||
|   | ||||
							
								
								
									
										10
									
								
								src/scripts/port-get.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								src/scripts/port-get.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,10 @@ | ||||
| import getPort from 'get-port'; | ||||
|  | ||||
| const port = 51015; | ||||
| const isPortAvailable = await getPort({ port: [51015, 51030] }); | ||||
| if (!isPortAvailable) { | ||||
|   console.log(`Port ${port} is not available`); | ||||
|   process.exit(1); | ||||
| } | ||||
| console.log(`Port ${isPortAvailable} is available`); | ||||
| process.exit(0); | ||||
		Reference in New Issue
	
	Block a user