diff --git a/Procfile b/Procfile deleted file mode 100644 index e8f79ea..0000000 --- a/Procfile +++ /dev/null @@ -1 +0,0 @@ -web: npm start \ No newline at end of file diff --git a/client/package-lock.json b/client/package-lock.json index 75de6b6..4b96dd8 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -15,6 +15,7 @@ "antd-img-crop": "^3.16.0", "axios": "^1.6.7", "dayjs": "^1.11.10", + "dompurify": "^2.4.7", "react": "^17.0.2", "react-dom": "^17.0.2", "react-infinite-scroll-component": "^6.1.0", @@ -24,7 +25,7 @@ "web-vitals": "^1.1.2" }, "devDependencies": { - "@babel/plugin-proposal-private-property-in-object": "*", + "@babel/plugin-proposal-private-property-in-object": "^7.21.11", "nodemon": "^3.0.3" }, "engines": { @@ -818,9 +819,17 @@ } }, "node_modules/@babel/plugin-proposal-private-property-in-object": { - "version": "7.21.0-placeholder-for-preset-env.2", - "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-private-property-in-object/-/plugin-proposal-private-property-in-object-7.21.0-placeholder-for-preset-env.2.tgz", - "integrity": "sha512-SOSkfJDddaM7mak6cPEpswyTRnuRltl429hMraQEglW+OkovnCzsiszTmsrlY//qLFjCpQDFRvjdm2wA5pPm9w==", + "version": "7.21.11", + "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-private-property-in-object/-/plugin-proposal-private-property-in-object-7.21.11.tgz", + "integrity": "sha512-0QZ8qP/3RLDVBwBFoWAwCtgcDZJVwA5LUJRZU8x2YFfKNuFq161wK3cuGrALu5yiPu+vzwTAg/sMWVNeWeNyaw==", + "deprecated": "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-private-property-in-object instead.", + "dev": true, + "dependencies": { + "@babel/helper-annotate-as-pure": "^7.18.6", + "@babel/helper-create-class-features-plugin": "^7.21.0", + "@babel/helper-plugin-utils": "^7.20.2", + "@babel/plugin-syntax-private-property-in-object": "^7.14.5" + }, "engines": { "node": ">=6.9.0" }, @@ -2063,6 +2072,17 @@ "@babel/core": "^7.0.0-0" } }, + "node_modules/@babel/preset-env/node_modules/@babel/plugin-proposal-private-property-in-object": { + "version": "7.21.0-placeholder-for-preset-env.2", + "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-private-property-in-object/-/plugin-proposal-private-property-in-object-7.21.0-placeholder-for-preset-env.2.tgz", + "integrity": "sha512-SOSkfJDddaM7mak6cPEpswyTRnuRltl429hMraQEglW+OkovnCzsiszTmsrlY//qLFjCpQDFRvjdm2wA5pPm9w==", + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, "node_modules/@babel/preset-env/node_modules/semver": { "version": "6.3.1", "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", @@ -7224,6 +7244,11 @@ "url": "https://github.com/fb55/domhandler?sponsor=1" } }, + "node_modules/dompurify": { + "version": "2.4.7", + "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-2.4.7.tgz", + "integrity": "sha512-kxxKlPEDa6Nc5WJi+qRgPbOAbgTpSULL+vI3NUXsZMlkJxTqYI9wg5ZTay2sFrdZRWHPWNi+EdAhcJf81WtoMQ==" + }, "node_modules/domutils": { "version": "2.8.0", "resolved": "https://registry.npmjs.org/domutils/-/domutils-2.8.0.tgz", diff --git a/client/package.json b/client/package.json index fb6adf4..e812149 100644 --- a/client/package.json +++ b/client/package.json @@ -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", diff --git a/client/src/components/Blog/CreateBlog.js b/client/src/components/Blog/CreateBlog.js index c919721..21d7749 100644 --- a/client/src/components/Blog/CreateBlog.js +++ b/client/src/components/Blog/CreateBlog.js @@ -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(() => { @@ -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')}`, } diff --git a/client/src/components/Blog/EditBlog.js b/client/src/components/Blog/EditBlog.js index 0563f8d..1b916cf 100644 --- a/client/src/components/Blog/EditBlog.js +++ b/client/src/components/Blog/EditBlog.js @@ -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' @@ -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('/') } @@ -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')}`, } diff --git a/client/src/components/Home/Home.js b/client/src/components/Home/Home.js index c6f1825..dd2fdd0 100644 --- a/client/src/components/Home/Home.js +++ b/client/src/components/Home/Home.js @@ -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" @@ -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=>{ diff --git a/client/src/components/login/login.js b/client/src/components/login/login.js index d764736..c92fbb8 100644 --- a/client/src/components/login/login.js +++ b/client/src/components/login/login.js @@ -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"; @@ -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) diff --git a/client/src/components/profile/EditProfile.js b/client/src/components/profile/EditProfile.js index a4f96cf..31e24f3 100644 --- a/client/src/components/profile/EditProfile.js +++ b/client/src/components/profile/EditProfile.js @@ -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"; @@ -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) @@ -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')}`, } diff --git a/client/src/components/profile/Profile.js b/client/src/components/profile/Profile.js index 482f620..decdb74 100644 --- a/client/src/components/profile/Profile.js +++ b/client/src/components/profile/Profile.js @@ -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' @@ -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 diff --git a/client/src/components/signup/Signup.js b/client/src/components/signup/Signup.js index f31b531..cf9c539 100644 --- a/client/src/components/signup/Signup.js +++ b/client/src/components/signup/Signup.js @@ -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'; @@ -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") diff --git a/client/src/router/axiosInstance.js b/client/src/router/axiosInstance.js new file mode 100644 index 0000000..5766e30 --- /dev/null +++ b/client/src/router/axiosInstance.js @@ -0,0 +1,7 @@ +import axios from "axios"; + +const instance = axios.create({ + baseURL: 'http://localhost:5000' + }); + +export default instance; \ No newline at end of file diff --git a/.gitignore b/server/.gitignore similarity index 100% rename from .gitignore rename to server/.gitignore diff --git a/LICENSE b/server/LICENSE similarity index 100% rename from LICENSE rename to server/LICENSE diff --git a/controllers/auth.js b/server/controllers/auth.js similarity index 100% rename from controllers/auth.js rename to server/controllers/auth.js diff --git a/controllers/blog.js b/server/controllers/blog.js similarity index 100% rename from controllers/blog.js rename to server/controllers/blog.js diff --git a/controllers/comment.js b/server/controllers/comment.js similarity index 100% rename from controllers/comment.js rename to server/controllers/comment.js diff --git a/controllers/file.js b/server/controllers/file.js similarity index 100% rename from controllers/file.js rename to server/controllers/file.js diff --git a/database/connect.js b/server/database/connect.js similarity index 100% rename from database/connect.js rename to server/database/connect.js diff --git a/middleware/asyncWrapper.js b/server/middleware/asyncWrapper.js similarity index 100% rename from middleware/asyncWrapper.js rename to server/middleware/asyncWrapper.js diff --git a/middleware/authentication.js b/server/middleware/authentication.js similarity index 100% rename from middleware/authentication.js rename to server/middleware/authentication.js diff --git a/middleware/error-handler.js b/server/middleware/error-handler.js similarity index 100% rename from middleware/error-handler.js rename to server/middleware/error-handler.js diff --git a/middleware/upload.js b/server/middleware/upload.js similarity index 100% rename from middleware/upload.js rename to server/middleware/upload.js diff --git a/models/blog.js b/server/models/blog.js similarity index 100% rename from models/blog.js rename to server/models/blog.js diff --git a/models/comment.js b/server/models/comment.js similarity index 100% rename from models/comment.js rename to server/models/comment.js diff --git a/models/user.js b/server/models/user.js similarity index 100% rename from models/user.js rename to server/models/user.js diff --git a/package-lock.json b/server/package-lock.json similarity index 100% rename from package-lock.json rename to server/package-lock.json diff --git a/package.json b/server/package.json similarity index 100% rename from package.json rename to server/package.json diff --git a/routes/auth.js b/server/routes/auth.js similarity index 100% rename from routes/auth.js rename to server/routes/auth.js diff --git a/routes/blog.js b/server/routes/blog.js similarity index 100% rename from routes/blog.js rename to server/routes/blog.js diff --git a/routes/comment.js b/server/routes/comment.js similarity index 100% rename from routes/comment.js rename to server/routes/comment.js diff --git a/routes/file.js b/server/routes/file.js similarity index 100% rename from routes/file.js rename to server/routes/file.js diff --git a/server.js b/server/server.js similarity index 94% rename from server.js rename to server/server.js index c54e64e..16ce97a 100644 --- a/server.js +++ b/server/server.js @@ -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); diff --git a/server/vercel.json b/server/vercel.json new file mode 100644 index 0000000..c7a6908 --- /dev/null +++ b/server/vercel.json @@ -0,0 +1,16 @@ +{ + "version": 2, + "buildCommand": "npm run build", + "builds": [ + { + "src": "server.js", + "use": "@vercel/node" + } + ], + "routes": [ + { + "src": "/(.*)", + "dest": "server.js" + } + ] +} \ No newline at end of file