Skip to content

Commit 923beef

Browse files
committed
refactor: changing client side to server side API
1 parent c0389e9 commit 923beef

File tree

7 files changed

+49
-15
lines changed

7 files changed

+49
-15
lines changed

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
API_URL=https://mxmdev.jamu.online/api

.env.local.sample

Lines changed: 0 additions & 1 deletion
This file was deleted.

.env.sample

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
API_URL=https://localhost:3000/api

next.config.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,27 @@
11
/** @type {import('next').NextConfig} */
2-
const nextConfig = {};
2+
3+
const withNextEnv = require("next-env");
4+
const dotenv = require("dotenv");
5+
const webpack = require("webpack");
6+
7+
dotenv.config();
8+
9+
const nextConfig = {
10+
experimental: {
11+
appDir: true,
12+
},
13+
env: {
14+
API_URL: process.env.API_URL,
15+
},
16+
};
17+
18+
module.exports = withNextEnv({
19+
reactStrictMode: true,
20+
webpack: (config) => {
21+
config.plugins.push(new webpack.EnvironmentPlugin(process.env));
22+
23+
return config;
24+
},
25+
});
326

427
module.exports = nextConfig;

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"framer-motion": "^10.12.18",
2929
"mui-datatables": "^4.3.0",
3030
"next": "13.4.6",
31+
"next-env": "^1.1.1",
3132
"postcss": "8.4.24",
3233
"react": "18.2.0",
3334
"react-apexcharts": "^1.4.1",

pnpm-lock.yaml

Lines changed: 20 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

services/api.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import axios, { isAxiosError, AxiosError } from "axios";
22
import Swal from "sweetalert2";
33

44
// !CHANGEME: hardcode
5-
export const baseUrl =
6-
process.env.NEXT_PUBLIC_API_URL ?? "http://localhost:3000/api";
5+
export const baseUrl = process.env.API_URL ?? "http://localhost:3000/api";
76

87
export const HandleAxiosError = (error: any) => {
98
if (!isAxiosError(error)) {
@@ -33,11 +32,7 @@ export const HandleAxiosError = (error: any) => {
3332
return;
3433
}
3534

36-
Swal.fire(
37-
"Error",
38-
response.data.message ?? "Terjadi kesalahan saat request",
39-
"error"
40-
);
35+
Swal.fire("Error", response.data.message ?? "Terjadi kesalahan saat request", "error");
4136
};
4237

4338
export type ResponseModel<T> = {

0 commit comments

Comments
 (0)