Skip to content

Commit

Permalink
add proxy to other routes + cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
s-alad committed Apr 5, 2024
1 parent e30cac4 commit d8b8853
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 58 deletions.
2 changes: 1 addition & 1 deletion client/pages/api/all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const config = {
maxDuration: 300,
}


// friends feed v1
export default async function handler(req: NextApiRequest, res: NextApiResponse) {

console.log("FETCHING FEED")
Expand Down
3 changes: 2 additions & 1 deletion client/pages/api/comment.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { NextApiRequest, NextApiResponse } from 'next'
import axios from 'axios';
import { getAuthHeaders } from '@/utils/authHeaders';
import { PROXY } from '@/utils/constants';

export default async function handler(req: NextApiRequest, res: NextApiResponse) {

Expand All @@ -16,7 +17,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
content: comment,
}
let options = {
url: "https://mobile.bereal.com/api" + "/content/comments" + "?postId=" + instance_id + "&postUserId=" + poster_user_id,
url: `${PROXY}https://mobile.bereal.com/api` + "/content/comments" + "?postId=" + instance_id + "&postUserId=" + poster_user_id,
method: "POST",
headers: getAuthHeaders(req.body.token),
data: body,
Expand Down
2 changes: 1 addition & 1 deletion client/pages/api/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const config = {
maxDuration: 300,
}


// deprecated
export default async function handler(req: NextApiRequest, res: NextApiResponse) {

console.log("FETCING FEED")
Expand Down
3 changes: 2 additions & 1 deletion client/pages/api/friends.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import type { NextApiRequest, NextApiResponse } from 'next'
import axios from 'axios';
import { getAuthHeaders } from '@/utils/authHeaders';
import { PROXY } from '@/utils/constants';

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
let authorization_token = req.body.token;
console.log("friends");
console.log(authorization_token);

return axios.request({
url: "https://mobile.bereal.com/api" + "/relationships/friends",
url: `${PROXY}https://mobile.bereal.com/api` + "/relationships/friends",
method: "GET",
headers: getAuthHeaders(req.body.token),
}).then(
Expand Down
3 changes: 2 additions & 1 deletion client/pages/api/memories.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { NextApiRequest, NextApiResponse } from 'next'
import axios from 'axios';
import { getAuthHeaders } from '@/utils/authHeaders';
import { PROXY } from '@/utils/constants';

export const config = {
api: {
Expand All @@ -16,7 +17,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
console.log(authorization_token);

return axios.request({
url: "https://mobile.bereal.com/api" + "/feeds/memories",
url: `${PROXY}https://mobile.bereal.com/api` + "/feeds/memories",
method: "GET",
headers: getAuthHeaders(req.body.token),
}).then(
Expand Down
3 changes: 2 additions & 1 deletion client/pages/api/profile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { NextApiRequest, NextApiResponse } from 'next'
import axios from 'axios';
import { getAuthHeaders } from '@/utils/authHeaders';
import { PROXY } from '@/utils/constants';

export default async function handler(req: NextApiRequest, res: NextApiResponse) {

Expand All @@ -10,7 +11,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
console.log(authorization_token, profile_id);

return axios.request({
url: "https://mobile.bereal.com/api" + `/person/profiles/${profile_id}`,
url: `${PROXY}https://mobile.bereal.com/api` + `/person/profiles/${profile_id}`,
method: "GET",
headers: getAuthHeaders(req.body.token),
}).then(
Expand Down
35 changes: 0 additions & 35 deletions client/pages/api/proxy.ts

This file was deleted.

3 changes: 2 additions & 1 deletion client/pages/api/react.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { NextApiRequest, NextApiResponse } from 'next'
import axios from 'axios';
import { getAuthHeaders } from '@/utils/authHeaders';
import { PROXY } from '@/utils/constants';

export default async function handler(req: NextApiRequest, res: NextApiResponse) {

Expand All @@ -22,7 +23,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
}

return axios.request({
url: "https://mobile.bereal.com/api" + `/content/realmojis`,
url: `${PROXY}https://mobile.bereal.com/api` + `/content/realmojis`,
method: "PUT",
headers: getAuthHeaders(req.body.token),
data: data,
Expand Down
27 changes: 11 additions & 16 deletions client/pages/feed/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,28 @@ export default function Feed() {
if (!useCheck()) {
return <></>
}
let [ready, setReady] = useState<boolean>(false);


let [instances, setInstances] = useState<{ [key: string]: Instance }>({})
let [loading, setLoading] = useState<boolean>(true);
let [failure, setFailure] = useState<string>("");

let [myinstances, setMyinstances] = useState<Instance[]>([]);

useEffect(() => {

setLoading(true);
let token = localStorage.getItem("token");
let body = JSON.stringify({ "token": token });
setReady(true);

/*
old feed api
let options = {
url: "/api/feed",
method: "POST",
headers: { 'Content-Type': 'application/json' },
data: body,
}
/* axios.request(options).then(
axios.request(options).then(
async (response) => {
console.log("response.data")
Expand Down Expand Up @@ -85,7 +84,8 @@ export default function Feed() {
setFailure("SOMETHING WENT WRONG: " + JSON.stringify(error.response.data.error));
setTimeout(() => {setFailure("")}, 5000);
}
) */
)
*/

let testoptions = {
url: "/api/all",
Expand All @@ -96,20 +96,16 @@ export default function Feed() {

axios.request(testoptions).then(
async (response) => {
console.log("=====================================")
console.log("all feed data")
console.log(response.data);
console.log("=====================================")

let newinstances: { [key: string]: Instance } = {};
async function createInstance(data: any, usr: any) {
/* console.log("CURRENT INSTANCE DATA");
console.log(data);
console.log("=====================================") */
let id = data.id;
let newinstance = await Instance.moment(data, usr);
newinstances[id] = newinstance;
/* console.log("newinstances");
console.log(newinstances); */
setLoading(false);
}

Expand Down Expand Up @@ -235,15 +231,14 @@ export default function Feed() {
onClick={closeAds}
/>
</div>
<Link href="https://ishemine.com" target="_blank" rel="noopener noreferrer" key={'link' + idx}>
<img src={"https://ishemine-bucket.s3.us-east-1.amazonaws.com/ihm-toofake.png"} alt="ad" key={'img' + idx} className={s.adimage} />
</Link>
</div>
);
}
return elements;
}) */
})
*/

loading ? <div className={l.loader}></div> :
(
Object.keys(instances).length > 0 ?
Expand Down

0 comments on commit d8b8853

Please sign in to comment.