This commit is contained in:
2026-07-06 07:30:48 +07:00
parent 647e13e988
commit dbd98dff37
12 changed files with 10559 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
import { Module } from '@nestjs/common';
import { ServeStaticModule } from '@nestjs/serve-static';
import { join } from 'path';
// Resolve the storage directory (default to ../storage relative to the compiled or source path)
const storageDir = process.env.STORAGE_DIR || join(__dirname, '..', '..', 'storage');
@Module({
imports: [
ServeStaticModule.forRoot({
rootPath: storageDir,
serveRoot: '/',
}),
],
})
export class AppModule { }

View File

@@ -0,0 +1,25 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { Logger } from '@nestjs/common';
import { join } from 'path';
async function bootstrap() {
const logger = new Logger('Bootstrap');
const app = await NestFactory.create(AppModule);
// Enable CORS for static file downloading/fetching across origins
app.enableCors({
origin: '*',
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS',
credentials: true,
});
const port = process.env.PORT ?? 8081;
const storageDir = process.env.STORAGE_DIR || join(__dirname, '..', '..', 'storage');
await app.listen(port);
logger.log(`Storage static file server is running on: http://localhost:${port}`);
logger.log(`Serving static files from: ${storageDir}`);
}
bootstrap();