From ecf202655a71e22d9766d409bea633a0db1f9a97 Mon Sep 17 00:00:00 2001
From: L4168 <L4168@student.jamk.fi>
Date: Tue, 23 Jul 2019 08:15:08 +0300
Subject: [PATCH] use controller to serve images

---
 src/game/game.controller.ts | 6 ++++++
 src/game/game.dto.ts        | 2 ++
 src/main.ts                 | 5 +----
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/game/game.controller.ts b/src/game/game.controller.ts
index 238f54c..b79699c 100644
--- a/src/game/game.controller.ts
+++ b/src/game/game.controller.ts
@@ -11,6 +11,7 @@ import {
   ClassSerializerInterceptor,
   Delete,
   UploadedFile,
+  Res,
 } from '@nestjs/common';
 import { FileInterceptor } from '@nestjs/platform-express';
 import { diskStorage } from 'multer';
@@ -126,4 +127,9 @@ export class GameController {
   uploadImage(@UploadedFile() image) {
     return image;
   }
+
+  @Get('images/:img')
+  returnImage(@Param('img') image, @Res() res) {
+    return res.sendFile(image, { root: 'images' });
+  }
 }
diff --git a/src/game/game.dto.ts b/src/game/game.dto.ts
index 081a9ae..e6d9986 100644
--- a/src/game/game.dto.ts
+++ b/src/game/game.dto.ts
@@ -73,6 +73,8 @@ export class newGameDTO {
   enddate: string;
   @Length(0, 65)
   image: string;
+  @Allow()
+  map?: JSON;
 }
 
 export class GameStateDTO {
diff --git a/src/main.ts b/src/main.ts
index e0a6253..ebd53e5 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -1,6 +1,4 @@
 import { NestFactory } from '@nestjs/core';
-import { NestExpressApplication } from '@nestjs/platform-express';
-import { join } from 'path';
 
 import { AppModule } from './app.module';
 
@@ -9,10 +7,9 @@ import { AppModule } from './app.module';
 */
 
 async function bootstrap() {
-  const app = await NestFactory.create<NestExpressApplication>(AppModule);
+  const app = await NestFactory.create(AppModule);
   // Cors is needed for application/json POST
   app.enableCors();
-  app.useStaticAssets(join(__dirname, '..', 'images'));
   await app.listen(5000);
 }
 bootstrap();
-- 
GitLab