Skip to content

Commit

Permalink
Fix Statics Serve
Browse files Browse the repository at this point in the history
  • Loading branch information
cpfriend1721994 committed Apr 2, 2024
1 parent e631234 commit 54f0580
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,11 @@ npm i @nnmt/platform-hyper-express
## Usage
```js
import { NestFactory } from '@nestjs/core';
import {
HyperExpressAdapter,
NestHyperExpressApplication,
} from '@nnmt/platform-hyper-express';
import { HyperExpressAdapter } from '@nnmt/platform-hyper-express';
import { AppModule } from './app.module';

async function bootstrap() {
const app = await NestFactory.create<NestHyperExpressApplication>(
const app = await NestFactory.create(
AppModule,
new HyperExpressAdapter()
);
Expand Down
24 changes: 15 additions & 9 deletions adapters/hyper-express-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
urlencoded as bodyParserUrlencoded,
} from 'body-parser';
import * as bodyparser from 'body-parser';
import * as cors from 'cors';
import cors = require('cors');
import { Server, ServerConstructorOptions, Request, Response } from 'hyper-express';
import LiveDirectory = require('live-directory');
import { Duplex, pipeline } from 'stream';
Expand Down Expand Up @@ -60,7 +60,9 @@ export class HyperExpressAdapter extends AbstractHttpAdapter<

constructor(private opts?: ServerConstructorOptions) {
super();

if (opts) {
this.opts = opts;
}
this.httpServer = this.instance = new Server(this.opts);
}

Expand Down Expand Up @@ -192,7 +194,10 @@ export class HyperExpressAdapter extends AbstractHttpAdapter<
}

public useStaticAssets(path: string, options: ServeStaticOptions) {
return this.use(LiveDirectory(path, options));
if (options && options.prefix) {
return this.use(options.prefix, new LiveDirectory(path) );
}
return this.use(new LiveDirectory(path));
}

public setBaseViewsDir(path: string | string[]) {
Expand Down Expand Up @@ -228,20 +233,21 @@ export class HyperExpressAdapter extends AbstractHttpAdapter<
}

public initHttpServer(options: NestApplicationOptions) {
if (options.httpsOptions) {
if (this.opts && options && options?.httpsOptions) {
this.opts.key_file_name = options.httpsOptions.key;
this.opts.cert_file_name = options.httpsOptions.cert;
this.opts.passphrase = options.httpsOptions.passphrase;
this.opts.passphrase = options.httpsOptions.passphrase;
}
if (options?.forceCloseConnections) {
if (this.opts && options?.forceCloseConnections) {
this.opts.auto_close = options.forceCloseConnections;
}
this.httpServer = new Server(this.opts);
}

public registerParserMiddleware(prefix?: string, rawBody?: boolean) {
const bodyParserJsonOptions = getBodyParserOptions(rawBody);
const bodyParserUrlencodedOptions = getBodyParserOptions(rawBody, {
public registerParserMiddleware(prefix?: string, rawBody?: boolean | undefined) {
const rawBodyBoolean: boolean = rawBody || true;
const bodyParserJsonOptions = getBodyParserOptions(rawBodyBoolean);
const bodyParserUrlencodedOptions = getBodyParserOptions(rawBodyBoolean, {
extended: true,
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nnmt/platform-hyper-express",
"version": "0.1.1",
"version": "0.1.2",
"description": "NestJS Hyper-Express Adapter (@nnmt/platform-hyper-express)",
"author": "Nguyen Nhat Minh Tu",
"license": "MIT",
Expand Down

0 comments on commit 54f0580

Please sign in to comment.