Skip to content

Commit

Permalink
Merge pull request #11 from adizafri2000/dev
Browse files Browse the repository at this point in the history
Updated domain and endpoints
  • Loading branch information
adizafri2000 authored Apr 14, 2024
2 parents 0d20ddf + 8c98c21 commit 1325d02
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_JOLLY_ISLAND_033EE1D00 }}
repo_token: ${{ secrets.GITHUB_TOKEN }} # Used for Github integrations (i.e. PR comments)
VITE_VIM_IP: ${{ secrets.VITE_VM_IP }}
API_URL: ${{ secrets.API_URL }}
action: "upload"
###### Repository/Build Configurations - These values can be configured to match your app requirements. ######
# For more information regarding Static Web App workflow configurations, please visit: https://aka.ms/swaworkflowconfig
Expand All @@ -45,5 +45,5 @@ jobs:
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_JOLLY_ISLAND_033EE1D00 }}
VITE_VIM_IP: ${{ secrets.VITE_VM_IP }}
API_URL: ${{ secrets.API_URL }}
action: "close"
5 changes: 5 additions & 0 deletions spring-boot-backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@
<artifactId>jjwt</artifactId>
<version>0.9.1</version>
</dependency>
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry-spring-boot-starter-jakarta</artifactId>
<version>7.6.0</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.csrf(csrf -> csrf.disable())
.authorizeHttpRequests((auth) -> auth
.requestMatchers("/actuator/**").permitAll()
.requestMatchers("/api/**").permitAll()
.requestMatchers("/**").permitAll()
.anyRequest().authenticated()
);
return http.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.example.springbootbackend.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.favorParameter(false).
ignoreAcceptHeader(true).
defaultContentType(MediaType.APPLICATION_JSON);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.example.springbootbackend.model.Account;
import com.example.springbootbackend.service.AccountService;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

Expand All @@ -16,11 +17,9 @@
import java.util.logging.Logger;

@RestController
@RequestMapping("/api/accounts")
@RequestMapping(path = "/accounts")
public class AccountController {

public static final String ACCOUNTS = "/api/accounts";

private static final Logger log = Logger.getLogger(AccountController.class.getName());
private final AccountService accountService;
private final AccountMapper accountMapper = AccountMapper.INSTANCE;
Expand All @@ -30,15 +29,17 @@ public AccountController(AccountService accountService) {
}

@GetMapping("")
public ResponseEntity<List<AccountGetDTO>> getAccounts() {
public ResponseEntity<?> getAccounts() {
log.info("Handling GET /api/accounts request");
List<AccountGetDTO> dtoList = accountService.getAccounts().stream()
.map(accountMapper::toGetDTO)
.toList();
return new ResponseEntity<>(dtoList, HttpStatus.OK);
Map<String, List<AccountGetDTO>> listResponse = new HashMap<>();
listResponse.put("accounts", dtoList);
return new ResponseEntity<>(listResponse, HttpStatus.OK);
}

@GetMapping("/{id}")
@GetMapping(path = "/{id}")
public ResponseEntity<?> getAccountById(@PathVariable Integer id) {
log.info("Handling GET /api/accounts/" + id + " request");
Account account = accountService.getAccountById(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.example.springbootbackend.repository.AccountRepository;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import io.sentry.Sentry;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -91,6 +92,7 @@ public String loginAccount(AccountLoginDTO accountLoginDTO) {
return generateToken(account);
}
}
Sentry.captureMessage("Invalid email or password");
throw new InvalidCredentialsException("Invalid email or password");
}

Expand Down
6 changes: 3 additions & 3 deletions web/src/services/accounts.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios'
const host = import.meta.env.VITE_VM_IP
const baseUrl = `http://${host}/api/accounts`
const host = import.meta.env.API_URL
const baseUrl = `${host}/accounts`

let token = null

Expand Down Expand Up @@ -34,4 +34,4 @@ const remove = async id => {
const response = await axios.delete(`${baseUrl}/${id}`, config)
}

export default { getAll, setToken, create, update, remove }
export default { getAll, setToken, create, update, remove }
8 changes: 4 additions & 4 deletions web/src/services/login.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import axios from 'axios'
const host = import.meta.env.VITE_VM_IP
// const baseUrl = `http://${host}/api/accounts/login`
const baseUrl = '/api/accounts/login'
const host = import.meta.env.API_URL
const baseUrl = `${host}/accounts/login`
//const baseUrl = '/accounts/login'

const login = async credentials => {
const response = await axios.post(baseUrl, credentials)
return response.data
}

export default { login }
export default { login }
9 changes: 5 additions & 4 deletions web/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ import dotenv from 'dotenv'

dotenv.config()

const IP = process.env.VITE_VM_IP;
//const IP = process.env.VM_IP;
const API_URL = process.env.API_URL

export default defineConfig({
plugins: [react()],
server: {
proxy: {
'/api': {
target: `http://${IP}`,
'/': {
target: `${API_URL}`,
changeOrigin: true,
},
}
},
})
})

0 comments on commit 1325d02

Please sign in to comment.