Skip to content

Commit

Permalink
Feat: Configure proxy for dev server
Browse files Browse the repository at this point in the history
  • Loading branch information
gabo71096 committed Aug 12, 2023
1 parent b4cb188 commit 5dacf86
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
2 changes: 2 additions & 0 deletions api/config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,6 @@

# Uncomment if you wish to allow Action Cable access from any origin.
# config.action_cable.disable_request_forgery_protection = true

config.hosts << 'api'
end
16 changes: 8 additions & 8 deletions api/config/initializers/cors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

# Read more: https://github.com/cyu/rack-cors

Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
origins 'http://localhost:5173'
# Rails.application.config.middleware.insert_before 0, Rack::Cors do
# allow do
# origins 'http://localhost:5173'

resource '*',
headers: :any,
methods: %i[get post put patch delete options head]
end
end
# resource '*',
# headers: :any,
# methods: %i[get post put patch delete options head]
# end
# end
3 changes: 2 additions & 1 deletion client/src/app/api/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import axios, { AxiosError, AxiosResponse } from "axios";
import { toast } from "react-toastify";
import { router } from "../router/Routes";

axios.defaults.baseURL = "/api/v1";

const sleep = () => new Promise((resolve) => setTimeout(resolve, 500));
axios.defaults.baseURL = "http://localhost:3000/api/v1";
const responseBody = (response: AxiosResponse) => response.data;

axios.interceptors.response.use(
Expand Down
8 changes: 8 additions & 0 deletions client/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@ export default defineConfig({
outDir: "../api/public",
emptyOutDir: true,
},
server: {
proxy: {
"/api/v1": {
target: "http://api:3000",
changeOrigin: true,
},
},
},
});

0 comments on commit 5dacf86

Please sign in to comment.