feat: added api proxy & image type

This commit is contained in:
Sergey Yarkov 2021-10-22 22:23:58 +03:00
parent 9a43ade63a
commit d997f99239
7 changed files with 23 additions and 6 deletions

1
constants.ts Normal file
View File

@ -0,0 +1 @@
export const BACKEND_URL: string = 'http://localhost:3333';

View File

@ -1,8 +1,7 @@
import { AxiosRequestConfig } from 'axios'; import { AxiosRequestConfig } from 'axios';
import * as constants from './constants';
const apiConfig: AxiosRequestConfig = { const apiConfig: AxiosRequestConfig = {
baseURL: constants.API_BASE_URL, baseURL: '/api/',
responseType: 'json', responseType: 'json',
withCredentials: true, withCredentials: true,
}; };

View File

@ -1 +0,0 @@
export const API_BASE_URL: string = 'http://localhost:3333/api';

View File

@ -1,5 +1,5 @@
import type { RouteComponentProps } from 'react-router-dom'; import type { RouteComponentProps } from 'react-router-dom';
import { LinkType } from '@educt/types'; import { CourseImage, LinkType } from '@educt/types';
import { CourseStatusEnum, UserRoleEnum } from '../enums'; import { CourseStatusEnum, UserRoleEnum } from '../enums';
export interface IAppConfig { export interface IAppConfig {
@ -21,7 +21,7 @@ export interface ICourse {
title: string; title: string;
description: string; description: string;
status: CourseStatusEnum; status: CourseStatusEnum;
image: null | {}; image: null | CourseImage;
teacher: Pick<IUser, 'id' | 'first_name' | 'last_name' | 'email'>; teacher: Pick<IUser, 'id' | 'first_name' | 'last_name' | 'email'>;
category: ICategory; category: ICategory;
lessons: ILesson[]; lessons: ILesson[];

View File

@ -31,6 +31,7 @@ import { useRootStore } from '@educt/hooks/useRootStore';
import CourseStatusBadge from '@educt/components/CourseStatusBadge'; import CourseStatusBadge from '@educt/components/CourseStatusBadge';
import { CourseStatusEnum } from '@educt/enums'; import { CourseStatusEnum } from '@educt/enums';
import { observer } from 'mobx-react'; import { observer } from 'mobx-react';
import { API_BASE_URL } from '@educt/constants';
type CourseItemPropsType = { type CourseItemPropsType = {
course: Omit<ICourse, 'teacher' | 'students' | 'lessons'>; course: Omit<ICourse, 'teacher' | 'students' | 'lessons'>;
@ -111,7 +112,7 @@ const CourseItem: React.FC<CourseItemPropsType> = ({ course, onDelete, onSetStat
w='100%' w='100%'
borderTopLeftRadius='lg' borderTopLeftRadius='lg'
borderTopRightRadius='lg' borderTopRightRadius='lg'
src='https://bit.ly/2k1H1t6' src={course.image ? `/api/assets/images/courses/${course.image.name}` : ''}
/> />
</Box> </Box>
<Box p='0 10px' mt='10px' pb='20px'> <Box p='0 10px' mt='10px' pb='20px'>

View File

@ -15,6 +15,14 @@ export type LinkType = {
icon: IconType; icon: IconType;
}; };
export type CourseImage = {
id: number;
name: string;
ext: string;
created_at: string;
updated_at: string;
};
export type ConfirmEmailContainerDataType = { export type ConfirmEmailContainerDataType = {
newEmail: string; newEmail: string;
expired_seconds: number; expired_seconds: number;

View File

@ -1,4 +1,5 @@
import { defineConfig } from 'vite'; import { defineConfig } from 'vite';
import * as constants from './constants';
import path from 'path'; import path from 'path';
import react from '@vitejs/plugin-react'; import react from '@vitejs/plugin-react';
import { visualizer } from 'rollup-plugin-visualizer'; import { visualizer } from 'rollup-plugin-visualizer';
@ -18,6 +19,14 @@ export default defineConfig({
root: './', root: './',
publicDir: 'public', publicDir: 'public',
plugins: [react()], plugins: [react()],
server: {
proxy: {
'/api': {
target: constants.BACKEND_URL,
changeOrigin: true,
},
},
},
resolve: { resolve: {
alias: [{ find: '@educt', replacement: path.resolve(__dirname, 'src') }], alias: [{ find: '@educt', replacement: path.resolve(__dirname, 'src') }],
}, },