diff --git a/src/consts.ts b/src/consts.ts index 972063f..b508d32 100644 --- a/src/consts.ts +++ b/src/consts.ts @@ -1,2 +1,3 @@ export const DB_NAME = '/store-service'; export const MONGO_URL = `mongodb://localhost:27017${DB_NAME}`; +export const ALLOW_ORIGIN_ALL: [string, string] = ['Access-Control-Allow-Origin', '*']; diff --git a/src/store/store.controller.ts b/src/store/store.controller.ts index 3f8dee5..0663222 100644 --- a/src/store/store.controller.ts +++ b/src/store/store.controller.ts @@ -1,7 +1,8 @@ -import { Controller, Get, Post, Body, Param } from '@nestjs/common'; +import { Controller, Get, Post, Body, Param, Header } from '@nestjs/common'; import {StoreService} from './store.service'; import {Store, StoreResponse, StoreRequest} from './store.schema'; import {ApiResponse} from '@nestjs/swagger'; +import {ALLOW_ORIGIN_ALL} from 'src/consts'; @Controller('store') export class StoreController { @@ -10,6 +11,7 @@ export class StoreController { ) {} @Get() + @Header(...ALLOW_ORIGIN_ALL) @ApiResponse({ status: 200, description: 'Список всех пар ключ-значение', @@ -20,6 +22,7 @@ export class StoreController { } @Get(':key?') + @Header(...ALLOW_ORIGIN_ALL) @ApiResponse({ status: 200, description: 'Возвращает пару ключ-значение по ключу', @@ -30,6 +33,7 @@ export class StoreController { } @Post() + @Header(...ALLOW_ORIGIN_ALL) @ApiResponse({ status: 200, description: 'Создает новую пару ключ-значение или заменяет существующую по ключу', diff --git a/store.http b/store.http index 52753fe..1aac84a 100644 --- a/store.http +++ b/store.http @@ -1,12 +1,12 @@ -GET http://localhost:3000/store HTTP/1.1 +GET http://localhost:4001/store HTTP/1.1 ### -GET http://localhost:3000/store/testApi HTTP/1.1 +GET http://localhost:4001/store/testApi HTTP/1.1 ### -POST http://localhost:3000/store HTTP/1.1 +POST http://localhost:4001/store HTTP/1.1 content-type: application/json {