Skip to content

Commit

Permalink
fix: listening and web config
Browse files Browse the repository at this point in the history
  • Loading branch information
cha0s committed Feb 18, 2024
1 parent e7353b8 commit 96f23f0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
14 changes: 10 additions & 4 deletions packages/web/src/server/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,17 @@ export const createHttpServer = async (flecks) => {
if (host) {
args.push(host);
}
args.push(async (error) => {
if (error) {
reject(error);
return;
const onError = (error) => {
if ('EADDRINUSE' === error.code) {
error.message = (
`HTTP server couldn't connect: '${[host, port].join(':')}' already in use!`
);
}
reject(error);
};
httpServer.on('error', onError);
args.push(async () => {
httpServer.off('error', onError);
await flecks.invokeSequentialAsync('@flecks/web/server.up', httpServer);
const actualPort = 0 === port ? httpServer.address().port : port;
debug(
Expand Down
16 changes: 9 additions & 7 deletions packages/web/src/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ const {
export {configSource};

export const hooks = {
'@flecks/core.starting': (flecks) => {
const {
host = 'production' === NODE_ENV ? '0.0.0.0' : 'localhost',
port,
public: httpPublic,
} = flecks.get('@flecks/web');
flecks.web.host = host;
flecks.web.public = httpPublic || [host, port].join(':');
},
'@flecks/web.routes': (flecks) => {
const routes = [
{
Expand Down Expand Up @@ -60,15 +69,8 @@ export const mixin = (Flecks) => class FlecksWithWeb extends Flecks {
constructor(runtime) {
super(runtime);
if (!this.web) {
const {
host = 'production' === NODE_ENV ? '0.0.0.0' : 'localhost',
port,
public: httpPublic,
} = runtime.config['@flecks/web'];
this.web = {
config: runtime['@flecks/web'],
host,
public: httpPublic || [host, port].join(':'),
server: undefined,
};
}
Expand Down

0 comments on commit 96f23f0

Please sign in to comment.