@@ -40,7 +40,7 @@ import {
4040const app = express ( ) ;
4141const PORT = 18103 ;
4242
43- app . use ( cors ( ) ) ;
43+ // app.use(cors());
4444app . use ( express . json ( ) ) ;
4545app . use ( ( req , _res , next ) => {
4646 if ( req . headers . cookie ) {
@@ -274,7 +274,7 @@ app.get("/get/tracking/:guild/:user", async (req, res) => {
274274 return res . status ( 200 ) . json ( data ) ;
275275} ) ;
276276
277- app . get ( "/get/:guild/:user" , async ( req , res ) => {
277+ app . get ( "/get/:guild/:user" , cors ( ) , async ( req , res ) => {
278278 const { guild, user } = req . params ;
279279
280280 const [ err , result ] = await getUser ( user , guild ) ;
@@ -289,7 +289,7 @@ app.get("/get/:guild/:user", async (req, res) => {
289289 }
290290} ) ;
291291
292- app . get ( "/get/:guild" , async ( req , res ) => {
292+ app . get ( "/get/:guild" , cors ( ) , async ( req , res ) => {
293293 const { guild } = req . params ;
294294
295295 const [ guildErr , guildData ] = await getGuild ( guild ) ;
@@ -834,8 +834,16 @@ app.get("/auth/callback", async (req, res) => {
834834 res . redirect ( `${ WEBSITE_URL } /dashboard` ) ;
835835} ) ;
836836
837+ app . options (
838+ "/user/me" ,
839+ cors ( {
840+ origin : [ "http://localhost:56413" , "https://chatr.fun" ] ,
841+ credentials : true ,
842+ } )
843+ ) ;
844+
837845app . get (
838- "/auth/ user" ,
846+ "/user/me " ,
839847 cors ( {
840848 origin : [ "http://localhost:56413" , "https://chatr.fun" ] ,
841849 credentials : true ,
@@ -854,8 +862,8 @@ app.get(
854862 }
855863) ;
856864
857- app . post (
858- "/auth/logout " ,
865+ app . delete (
866+ "/user/me " ,
859867 cors ( {
860868 origin : [ "http://localhost:56413" , "https://chatr.fun" ] ,
861869 credentials : true ,
@@ -871,7 +879,48 @@ app.post(
871879 }
872880) ;
873881
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 ) => {
875924 const user = await getUserFromRequest ( req ) ;
876925
877926 if ( ! user ) return res . status ( 401 ) . json ( { message : "Unauthorized" } ) ;
@@ -925,49 +974,9 @@ app.get("/auth/user/guilds", async (req, res) => {
925974 ) ;
926975} ) ;
927976
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-
968977// TODO: fetch from the bot itself using discord.js
969978// (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 ) => {
971980 const { guild } = req . params ;
972981
973982 const channelsResponse = await fetch (
0 commit comments