Skip to content

Commit

Permalink
struct-change
Browse files Browse the repository at this point in the history
  • Loading branch information
pemba1s1 committed Feb 13, 2024
1 parent 1286b43 commit 947badb
Show file tree
Hide file tree
Showing 33 changed files with 70 additions and 23 deletions.
1 change: 0 additions & 1 deletion Procfile

This file was deleted.

33 changes: 29 additions & 4 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
},
"dependencies": {
"@testing-library/jest-dom": "^5.17.0",
"dompurify": "^2.4.7",
"@testing-library/react": "^11.2.7",
"@testing-library/user-event": "^12.8.3",
"antd": "^4.24.15",
Expand Down
6 changes: 3 additions & 3 deletions client/src/components/Blog/CreateBlog.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import {
Upload
} from 'antd';
import { LoadingOutlined,UploadOutlined } from '@ant-design/icons';
import axios from "axios";
import { useNavigate } from "react-router";
import { useState,useEffect } from "react";
import ReactQuill from 'react-quill';
import 'react-quill/dist/quill.snow.css';
import instance from "../../router/axiosInstance";

const dummyRequest = ({ file, onSuccess }) => {
setTimeout(() => {
Expand Down Expand Up @@ -53,14 +53,14 @@ export default function CreateBlog() {
const fd = new FormData();
fd.append('file', file, file.name);
console.log(values)
await axios.post('/file/upload',fd,{
await instance.post('/file/upload',fd,{
headers:{
Authorization: `Bearer ${localStorage.getItem('token')}`,
}
}).then(res=>{
console.log(res.data)
values = {...values,photo:res.data}
axios.post('/api/v1/blogs',values,{
instance.post('/api/v1/blogs',values,{
headers:{
Authorization: `Bearer ${localStorage.getItem('token')}`,
}
Expand Down
6 changes: 3 additions & 3 deletions client/src/components/Blog/EditBlog.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Upload
} from 'antd';
import { LoadingOutlined,UploadOutlined } from '@ant-design/icons';
import axios from "axios";
import instance from "../../router/axiosInstance";
import { useNavigate,useParams } from "react-router";
import { useEffect,useState } from "react";
import {Edit} from './../../services/Blog'
Expand Down Expand Up @@ -47,7 +47,7 @@ export default function EditBlog() {
let navigate=useNavigate()
useEffect(() => {
async function fetchData(){
axios.get(`/api/v1/blogs/${params.id}`).then(res=>{
instance.get(`/api/v1/blogs/${params.id}`).then(res=>{
if(res.data.blog.writer._id!==localStorage.getItem('userId')){
navigate('/')
}
Expand All @@ -66,7 +66,7 @@ export default function EditBlog() {
setLoad(true)
const fd = new FormData();
fd.append('file', file, file.name);
await axios.post('/file/upload',fd,{
await instance.post('/file/upload',fd,{
headers:{
Authorization: `Bearer ${localStorage.getItem('token')}`,
}
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/Home/Home.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Content } from "antd/lib/layout/layout";
import { List, Avatar, Skeleton,Image } from 'antd';
import axios from "axios";
import instance from "../../router/axiosInstance";
import { useState,useEffect } from "react";
import { Link } from "react-router-dom";
import dayjs from "dayjs"
Expand All @@ -11,7 +11,7 @@ export default function Home() {

useEffect(() => {
async function fetchData(){
await axios.get('/api/v1/blogs').then(res=>{
await instance.get('/api/v1/blogs').then(res=>{
setBlogs(res.data.blogs)
setLoading(false)
},err=>{
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/login/login.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Content } from "antd/lib/layout/layout";
import {Form, Input, Button, Checkbox,Spin} from 'antd'
import { UserOutlined, LockOutlined,LoadingOutlined } from '@ant-design/icons';
import axios from "axios";
import instance from "../../router/axiosInstance";
import { Link,useNavigate } from "react-router-dom";
import { useState } from "react";

Expand All @@ -13,7 +13,7 @@ export default function Login() {
const onFinish = async (values) => {
setErr("")
setLoad(true)
await axios.post('/api/user/login',values).then(res=>{
await instance.post('/api/user/login',values).then(res=>{
localStorage.setItem('token',res.data.token)
localStorage.setItem('userId',res.data.user.userId)
localStorage.setItem('avatar',res.data.user.avatar)
Expand Down
6 changes: 3 additions & 3 deletions client/src/components/profile/EditProfile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Button, Form, Input,Spin,Upload } from "antd";
import { Content } from "antd/lib/layout/layout";
import axios from "axios";
import instance from "../../router/axiosInstance";
import { useState,useEffect } from "react";
import { LoadingOutlined } from '@ant-design/icons';
import { useParams } from "react-router-dom";
Expand All @@ -19,7 +19,7 @@ export default function EditProfile() {
const [form] = Form.useForm()

async function fetchData(){
await axios.get(`/api/user/${params.username}`).then(res=>{
await instance.get(`/api/user/${params.username}`).then(res=>{
setUser(res.data.user)
document.title = "Edit | "+res.data.user.username
setLoading(false)
Expand All @@ -44,7 +44,7 @@ export default function EditProfile() {
console.log(file)
const fd = new FormData();
fd.append('file', file, file.name);
await axios.post('/file/upload',fd,{
await instance.post('/file/upload',fd,{
headers:{
Authorization: `Bearer ${localStorage.getItem('token')}`,
}
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/profile/Profile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Content } from "antd/lib/layout/layout";
import { List, Avatar, Button, Skeleton, Image,Affix } from 'antd';
import axios from "axios";
import instance from "../../router/axiosInstance";
import { useState,useEffect } from "react";
import { Link,useParams } from "react-router-dom";
import { Del} from './../../services/Blog'
Expand All @@ -13,7 +13,7 @@ export default function Profile() {
let [loading,setLoading] = useState(true)

async function fetchData(){
await axios.get(`/api/v1/blogs/user/${params.username}`).then(res=>{
await instance.get(`/api/v1/blogs/user/${params.username}`).then(res=>{
setBlogs(res.data.userBlogs)
setUser(res.data.user)
document.title = params.username
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/signup/Signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
Button,
Spin
} from 'antd';
import axios from "axios";
import instance from "../../router/axiosInstance";
import { useNavigate } from "react-router";
import {useState} from 'react'
import { LoadingOutlined } from '@ant-design/icons';
Expand All @@ -19,7 +19,7 @@ export default function Signup() {
const onFinish = async(values) => {
setErr('')
setLoad(true)
await axios.post('/api/user/signup',values).then(res=>{
await instance.post('/api/user/signup',values).then(res=>{
console.log(res)
setLoad(false)
navigate("/login")
Expand Down
7 changes: 7 additions & 0 deletions client/src/router/axiosInstance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import axios from "axios";

const instance = axios.create({
baseURL: 'http://localhost:5000'
});

export default instance;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion server.js → server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ require('dotenv').config()
app.use(cors())
app.use(express.json())

app.use('/', express.static(path.join(__dirname, '/client/build')));
app.use('/api/v1/blogs',blogRoute)
app.use('/api/user',authRoute)
app.use("/file", file);
Expand Down
16 changes: 16 additions & 0 deletions server/vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"version": 2,
"buildCommand": "npm run build",
"builds": [
{
"src": "server.js",
"use": "@vercel/node"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "server.js"
}
]
}

0 comments on commit 947badb

Please sign in to comment.