@@ -40,7 +40,7 @@ import {
40
40
const app = express ( ) ;
41
41
const PORT = 18103 ;
42
42
43
- app . use ( cors ( ) ) ;
43
+ // app.use(cors());
44
44
app . use ( express . json ( ) ) ;
45
45
app . use ( ( req , _res , next ) => {
46
46
if ( req . headers . cookie ) {
@@ -274,7 +274,7 @@ app.get("/get/tracking/:guild/:user", async (req, res) => {
274
274
return res . status ( 200 ) . json ( data ) ;
275
275
} ) ;
276
276
277
- app . get ( "/get/:guild/:user" , async ( req , res ) => {
277
+ app . get ( "/get/:guild/:user" , cors ( ) , async ( req , res ) => {
278
278
const { guild, user } = req . params ;
279
279
280
280
const [ err , result ] = await getUser ( user , guild ) ;
@@ -289,7 +289,7 @@ app.get("/get/:guild/:user", async (req, res) => {
289
289
}
290
290
} ) ;
291
291
292
- app . get ( "/get/:guild" , async ( req , res ) => {
292
+ app . get ( "/get/:guild" , cors ( ) , async ( req , res ) => {
293
293
const { guild } = req . params ;
294
294
295
295
const [ guildErr , guildData ] = await getGuild ( guild ) ;
@@ -834,8 +834,16 @@ app.get("/auth/callback", async (req, res) => {
834
834
res . redirect ( `${ WEBSITE_URL } /dashboard` ) ;
835
835
} ) ;
836
836
837
+ app . options (
838
+ "/user/me" ,
839
+ cors ( {
840
+ origin : [ "http://localhost:56413" , "https://chatr.fun" ] ,
841
+ credentials : true ,
842
+ } )
843
+ ) ;
844
+
837
845
app . get (
838
- "/auth/ user" ,
846
+ "/user/me " ,
839
847
cors ( {
840
848
origin : [ "http://localhost:56413" , "https://chatr.fun" ] ,
841
849
credentials : true ,
@@ -854,8 +862,8 @@ app.get(
854
862
}
855
863
) ;
856
864
857
- app . post (
858
- "/auth/logout " ,
865
+ app . delete (
866
+ "/user/me " ,
859
867
cors ( {
860
868
origin : [ "http://localhost:56413" , "https://chatr.fun" ] ,
861
869
credentials : true ,
@@ -871,7 +879,48 @@ app.post(
871
879
}
872
880
) ;
873
881
874
- app . get ( "/auth/user/guilds" , async ( req , res ) => {
882
+ app . options (
883
+ "/dashboard/update-guild" ,
884
+ cors ( {
885
+ origin : [ "http://localhost:56413" , "https://chatr.fun" ] ,
886
+ credentials : true ,
887
+ } )
888
+ ) ;
889
+
890
+ app . post (
891
+ "/dashboard/update-guild" ,
892
+ cors ( {
893
+ origin : [ "http://localhost:56413" , "https://chatr.fun" ] ,
894
+ credentials : true ,
895
+ } ) ,
896
+ async ( req , res ) => {
897
+ if ( ! ( await getUserFromRequest ( req ) ) )
898
+ return res . status ( 401 ) . json ( { message : "Unauthorized" } ) ;
899
+
900
+ const body = req . body ;
901
+ const { guild } = req . body ;
902
+
903
+ if ( ! guild ) return res . status ( 400 ) . json ( { message : "Illegal request" } ) ;
904
+
905
+ if ( body . cooldown ) {
906
+ await setCooldown ( guild , body . cooldown ) ;
907
+ }
908
+
909
+ if ( body . updates . enabled === true ) {
910
+ await enableUpdates ( guild ) ;
911
+ } else if ( body . updates . enabled === false ) {
912
+ await disableUpdates ( guild ) ;
913
+ }
914
+
915
+ if ( body . updates . channel ) {
916
+ await setUpdatesChannel ( guild , body . updates . channel ) ;
917
+ }
918
+
919
+ return res . sendStatus ( 200 ) ;
920
+ }
921
+ ) ;
922
+
923
+ app . get ( "/user/me/guilds" , async ( req , res ) => {
875
924
const user = await getUserFromRequest ( req ) ;
876
925
877
926
if ( ! user ) return res . status ( 401 ) . json ( { message : "Unauthorized" } ) ;
@@ -925,49 +974,9 @@ app.get("/auth/user/guilds", async (req, res) => {
925
974
) ;
926
975
} ) ;
927
976
928
- app . options (
929
- "/auth/update-guild" ,
930
- cors ( {
931
- origin : [ "http://localhost:56413" , "https://chatr.fun" ] ,
932
- credentials : true ,
933
- } )
934
- ) ;
935
- app . put (
936
- "/auth/update-guild" ,
937
- cors ( {
938
- origin : [ "http://localhost:56413" , "https://chatr.fun" ] ,
939
- credentials : true ,
940
- } ) ,
941
- async ( req , res ) => {
942
- if ( ! ( await getUserFromRequest ( req ) ) )
943
- return res . status ( 401 ) . json ( { message : "Unauthorized" } ) ;
944
-
945
- const body = req . body ;
946
- const { guild } = req . body ;
947
-
948
- if ( ! guild ) return res . status ( 400 ) . json ( { message : "Illegal request" } ) ;
949
-
950
- if ( body . cooldown ) {
951
- await setCooldown ( guild , body . cooldown ) ;
952
- }
953
-
954
- if ( body . updates . enabled === true ) {
955
- await enableUpdates ( guild ) ;
956
- } else if ( body . updates . enabled === false ) {
957
- await disableUpdates ( guild ) ;
958
- }
959
-
960
- if ( body . updates . channel ) {
961
- await setUpdatesChannel ( guild , body . updates . channel ) ;
962
- }
963
-
964
- return res . sendStatus ( 204 ) ;
965
- }
966
- ) ;
967
-
968
977
// TODO: fetch from the bot itself using discord.js
969
978
// (would allow us to do permission filtering)
970
- app . get ( "/channels/:guild" , authMiddleware , async ( req , res ) => {
979
+ app . get ( "/dashboard/ channels/:guild" , authMiddleware , async ( req , res ) => {
971
980
const { guild } = req . params ;
972
981
973
982
const channelsResponse = await fetch (
0 commit comments