Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions integrations/sample-app/config/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ export default registerNamespace(
*/
url: process.env.APP_URL || 'localhost',

/**
* -----------------------------------------------------
* Hostname
* -----------------------------------------------------
*
* This address to bind the HTTP Listener to.
*/
hostname: process.env.HOSTNAME || '0.0.0.0',

/**
* -----------------------------------------------------
* Application Port
Expand Down
14 changes: 0 additions & 14 deletions packages/core/lib/database/service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { Injectable, OnModuleInit } from '@nestjs/common';
import Knex, { Knex as KnexType } from 'knex';
import { logTime } from '../utils/helpers';
import { InternalLogger } from '../utils/logger';
import { BaseModel } from './baseModel';
import { ConnectionNotFound } from './exceptions';
import { DatabaseOptions, DbConnectionOptions } from './options';
Expand Down Expand Up @@ -33,20 +31,8 @@ export class ObjectionService implements OnModuleInit {

try {
await connection.raw(dbOptions.validateQuery || 'select 1+1 as result');
InternalLogger.success(
'DatabaseService',
`Was able to successfully validate [${connName}] connection ${logTime(
Date.now() - time,
)}`,
);
} catch (_e) {
const e = _e as Error;
InternalLogger.error(
'DatabaseService',
`Validation for connection [${connName}] failed with reason ${
e.message
} ${logTime(Date.now() - time)}`,
);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/core/lib/interfaces/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface AppConfig {
env: string;
debug: boolean;
url: string;
hostname?: string;
port: number;
cors: CorsOptions | CorsOptionsDelegate<any>;
error?: {
Expand Down
43 changes: 35 additions & 8 deletions packages/core/lib/rest/foundation/server.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { HttpAdapterHost, NestFactory } from '@nestjs/core';
import { NestExpressApplication } from '@nestjs/platform-express';
import { useContainer } from 'class-validator';
// import 'console.mute';
import { ConfigService } from '../../config/service';
import { IntentExceptionFilter } from '../../exceptions';
import { IntentAppContainer, ModuleBuilder } from '../../foundation';
import { Type } from '../../interfaces';
import { Obj, Package } from '../../utils';
import { Kernel } from '../foundation/kernel';
import { requestMiddleware } from '../middlewares/functional/requestSerializer';
import pc from 'picocolors';
import { printBulletPoints } from '../../utils/console-helpers';
import 'console.mute';

export class IntentHttpServer {
private kernel: Kernel;
Expand Down Expand Up @@ -36,11 +38,11 @@ export class IntentHttpServer {
}

async start() {
console['mute']();
const module = ModuleBuilder.build(this.container, this.kernel);

// console['mute']();
const app = await NestFactory.create<NestExpressApplication>(module, {
bodyParser: true,
logger: false,
});

if (this.errorHandler) {
Expand All @@ -52,8 +54,6 @@ export class IntentHttpServer {
app.useBodyParser('raw');
app.useBodyParser('urlencoded');

// console['resume']();

app.use(requestMiddleware);

useContainer(app.select(module), { fallbackOnErrors: true });
Expand All @@ -64,9 +64,36 @@ export class IntentHttpServer {

this.configureErrorReporter(config.get('app.sentry'));

// options?.globalPrefix && app.setGlobalPrefix(options.globalPrefix);
console.log('server listening on ===> ');
await app.listen((config.get('app.port') as number) || 5001);
const port = config.get('app.port');
const hostname = config.get('app.hostname');
const environment = config.get('app.env');
const debug = config.get('app.debug');

await app.listen(+port || 5001, hostname);

console['resume']();

console.clear();

console.log(` ${pc.green(pc.bold('Intent'))} ${pc.green('v1.5.0')}`);
console.log();

printBulletPoints([
['➜', 'environment', environment],
['➜', 'debug', debug],
['➜', 'hostname', hostname],
['➜', 'port', port],
]);

const url = new URL(
['127.0.0.1', '0.0.0.0'].includes(hostname)
? 'http://localhost'
: `http://${hostname}`,
);
url.port = port;

console.log();
console.log(` ${pc.white('Listening on')}: ${pc.cyan(url.toString())}`);
}

configureErrorReporter(config: Record<string, any>) {
Expand Down
1 change: 0 additions & 1 deletion packages/core/lib/storage/service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Injectable } from '@nestjs/common';
import { LocalDiskOptions, S3DiskOptions } from './interfaces';
import { StorageDriver } from './interfaces';
import { InternalLogger } from '../utils/logger';
import { DiskNotFoundException } from './exceptions/diskNotFound';
import { ConfigService } from '../config';
import { DriverMap } from './driver-mapper';
Expand Down
9 changes: 9 additions & 0 deletions packages/core/lib/utils/console-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,12 @@ export const jsonToArchy = (obj: Record<string, any>, key = '') => {

return { label, nodes };
};

export const printBulletPoints = (rows: string[][]) => {
for (const row of rows) {
const [style, attribute, value] = row;
console.log(
` ${pc.green(pc.dim(style))} ${pc.white(attribute)}: ${pc.yellow(value)}`,
);
}
};