Skip to content

Commit

Permalink
Merge pull request #49 from JumboCode/myi/backend-deployment
Browse files Browse the repository at this point in the history
deploying express backend on vercel
  • Loading branch information
myix765 authored Nov 18, 2024
2 parents b1c0419 + d80cedd commit b2668d6
Show file tree
Hide file tree
Showing 11 changed files with 188 additions and 163 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ npm run client
To run just server:
```
npm run server # in root folder
npm run dev # in backend folder
npm run dev # in api folder
```

## Git Commands Guide
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions backend/package.json → api/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "backend",
"name": "api",
"version": "1.0.0",
"description": "",
"main": "server.js",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js",
"dev": "nodemon server"
"start": "node index.js",
"dev": "nodemon index"
},
"keywords": [],
"author": "",
Expand All @@ -22,4 +22,4 @@
"devDependencies": {
"nodemon": "^3.1.7"
}
}
}
279 changes: 136 additions & 143 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "module",
"scripts": {
"client": "vite",
"server": "npm run dev --prefix backend",
"server": "npm run dev --prefix api",
"dev": "concurrently \"npm run client\" \"npm run server\" \"npm i\"",
"build": "vite build",
"lint": "eslint .",
Expand Down Expand Up @@ -40,6 +40,6 @@
"vite": "^5.4.9"
},
"workspaces": [
"backend"
"api"
]
}
2 changes: 1 addition & 1 deletion src/api/class-wrapper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios'

const apiUrl = (endpoint) => `${import.meta.env.VITE_API_URL}${endpoint}`
const apiUrl = (endpoint) => `${endpoint}`

// query should be a string
const getClasses = async (query = "") => {
Expand Down
2 changes: 1 addition & 1 deletion src/api/contact-wrapper.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const apiUrl = (endpoint) => `${import.meta.env.VITE_API_URL}${endpoint}`
const apiUrl = (endpoint) => `${endpoint}`

const postContact = async (body) => {
try {
Expand Down
2 changes: 1 addition & 1 deletion src/api/user-wrapper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios';

const apiUrl = (endpoint) => `${import.meta.env.VITE_API_URL}${endpoint}`
const apiUrl = (endpoint) => `${endpoint}`

const postUser = async (body) => {
try {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Levels.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ const Levels = () => {
{levels.map((level, levelIndex) => {
params.set("level", level.level)
return (
<Link href={`/classes?${params.toString()}`}>
<Level key={levelIndex} level={level} />
<Link key={levelIndex} href={`/classes?${params.toString()}`}>
<Level level={level} />
</Link>
)
})}
Expand Down
41 changes: 34 additions & 7 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,35 @@
{
"rewrites": [
{
"source": "/((?!api/)[^./]+)",
"destination": "/"
}
]
}
"rewrites": [
{
"source": "/((?!api/)[^./]+)",
"destination": "/"
},
{
"source": "/api/(.*)",
"destination": "/api"
}
],
"headers": [
{
"source": "/api/(.*)",
"headers": [
{
"key": "Access-Control-Allow-Credentials",
"value": "true"
},
{
"key": "Access-Control-Allow-Origin",
"value": "*"
},
{
"key": "Access-Control-Allow-Methods",
"value": "GET,OPTIONS,PATCH,DELETE,POST,PUT"
},
{
"key": "Access-Control-Allow-Headers",
"value": "X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version"
}
]
}
]
}
5 changes: 5 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@ export default defineConfig({
'@': path.resolve(__dirname, 'src'),
},
},
server: {
proxy: {
'/api': "http://localhost:4000",
},
},
})

0 comments on commit b2668d6

Please sign in to comment.