-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- separate app start from task start, allows for multiple app workers - rename helper files
- Loading branch information
Showing
86 changed files
with
683 additions
and
427 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export declare const app: import("express-serve-static-core").Express; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// eslint-disable-next-line @eslint-community/eslint-comments/disable-enable-pair | ||
/* eslint-disable unicorn/no-process-exit */ | ||
import http from 'node:http'; | ||
import Debug from 'debug'; | ||
import exitHook from 'exit-hook'; | ||
import { getConfigProperty } from '../helpers/config.functions.js'; | ||
import { app } from './app.js'; | ||
const debug = Debug(`faster-web-helper:appProcess:${process.pid}`); | ||
function onError(error) { | ||
if (error.syscall !== 'listen') { | ||
throw error; | ||
} | ||
// handle specific listen errors with friendly messages | ||
switch (error.code) { | ||
case 'EACCES': { | ||
debug('Requires elevated privileges'); | ||
process.exit(1); | ||
// break; | ||
} | ||
// eslint-disable-next-line no-fallthrough | ||
case 'EADDRINUSE': { | ||
debug('Port is already in use.'); | ||
process.exit(1); | ||
// break; | ||
} | ||
// eslint-disable-next-line no-fallthrough | ||
default: { | ||
throw error; | ||
} | ||
} | ||
} | ||
function onListening(server) { | ||
const addr = server.address(); | ||
if (addr !== null) { | ||
const bind = typeof addr === 'string' ? `pipe ${addr}` : `port ${addr.port.toString()}`; | ||
debug(`HTTP Listening on ${bind}`); | ||
} | ||
} | ||
/* | ||
* Initialize HTTP | ||
*/ | ||
process.title = `Faster Web Helper (Worker)`; | ||
const httpPort = getConfigProperty('webServer.httpPort'); | ||
// eslint-disable-next-line @typescript-eslint/no-misused-promises | ||
const httpServer = http.createServer(app); | ||
httpServer.listen(httpPort); | ||
httpServer.on('error', onError); | ||
httpServer.on('listening', () => { | ||
onListening(httpServer); | ||
}); | ||
exitHook(() => { | ||
debug('Closing HTTP'); | ||
httpServer.close(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// eslint-disable-next-line @eslint-community/eslint-comments/disable-enable-pair | ||
/* eslint-disable unicorn/no-process-exit */ | ||
|
||
import http from 'node:http' | ||
|
||
import Debug from 'debug' | ||
import exitHook from 'exit-hook' | ||
|
||
import { getConfigProperty } from '../helpers/config.functions.js' | ||
|
||
import { app } from './app.js' | ||
|
||
const debug = Debug(`faster-web-helper:appProcess:${process.pid}`) | ||
|
||
interface ServerError extends Error { | ||
syscall: string | ||
code: string | ||
} | ||
|
||
function onError(error: ServerError): void { | ||
if (error.syscall !== 'listen') { | ||
throw error | ||
} | ||
|
||
// handle specific listen errors with friendly messages | ||
switch (error.code) { | ||
case 'EACCES': { | ||
debug('Requires elevated privileges') | ||
process.exit(1) | ||
// break; | ||
} | ||
|
||
// eslint-disable-next-line no-fallthrough | ||
case 'EADDRINUSE': { | ||
debug('Port is already in use.') | ||
process.exit(1) | ||
// break; | ||
} | ||
|
||
// eslint-disable-next-line no-fallthrough | ||
default: { | ||
throw error | ||
} | ||
} | ||
} | ||
|
||
function onListening(server: http.Server): void { | ||
const addr = server.address() | ||
|
||
if (addr !== null) { | ||
const bind = | ||
typeof addr === 'string' ? `pipe ${addr}` : `port ${addr.port.toString()}` | ||
debug(`HTTP Listening on ${bind}`) | ||
} | ||
} | ||
|
||
/* | ||
* Initialize HTTP | ||
*/ | ||
|
||
process.title = `Faster Web Helper (Worker)` | ||
|
||
const httpPort = getConfigProperty('webServer.httpPort') | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-misused-promises | ||
const httpServer = http.createServer(app) | ||
|
||
httpServer.listen(httpPort) | ||
|
||
httpServer.on('error', onError) | ||
httpServer.on('listening', () => { | ||
onListening(httpServer) | ||
}) | ||
|
||
exitHook(() => { | ||
debug('Closing HTTP') | ||
httpServer.close() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.