api change for weird cors

This commit is contained in:
Drake Marino 2024-06-27 10:41:34 -05:00
parent 1a6bf08bde
commit b92626b677

View File

@ -154,6 +154,7 @@ Future<String> fetchBusinessData() async {
//set defaults
String _hostname = 'localhost';
const _port = 8000;
Map<String, String> headers = {...headers, 'Access-Control-Allow-Methods': '*'};
final postgres = PostgreSQLConnection(
Platform.environment['JOBLINK_POSTGRES_ADDRESS']!,
@ -174,7 +175,7 @@ void main() async {
return Response.ok(
'Hello, World!',
headers: {'Access-Control-Allow-Origin': '*'},
headers: headers,
);
});
app.get('/fbla-api/businessdata/overview/jobs', (Request request) async {
@ -231,10 +232,7 @@ void main() async {
return Response.ok(
json.encode(postgresResult[0][0]),
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'text/plain'
},
headers: {...headers, 'Content-Type': 'text/plain'},
);
});
app.get('/fbla-api/businessdata/overview/types', (Request request) async {
@ -269,10 +267,7 @@ void main() async {
return Response.ok(
json.encode(output),
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'text/plain'
},
headers: {...headers, 'Content-Type': 'text/plain'},
);
});
app.get('/fbla-api/businessdata/businessnames', (Request request) async {
@ -289,10 +284,7 @@ void main() async {
return Response.ok(
json.encode(postgresResult),
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'text/plain'
},
headers: {...headers, 'Content-Type': 'text/plain'},
);
});
app.get('/fbla-api/businessdata/business/<business>',
@ -338,10 +330,7 @@ void main() async {
return Response.ok(
json.encode(result),
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'text/plain'
},
headers: {...headers, 'Content-Type': 'text/plain'},
);
});
app.get('/fbla-api/businessdata/businesses', (Request request) async {
@ -350,10 +339,7 @@ void main() async {
if (request.url.queryParameters['businesses'] == null) {
return Response.badRequest(
body: 'query \'businesses\' required',
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'text/plain'
},
headers: {...headers, 'Content-Type': 'text/plain'},
);
}
var filters = request.url.queryParameters['businesses']!.split(',');
@ -383,10 +369,7 @@ void main() async {
return Response.ok(
json.encode(output),
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'text/plain'
},
headers: {...headers, 'Content-Type': 'text/plain'},
);
});
app.get('/fbla-api/businessdata', (Request request) async {
@ -412,10 +395,7 @@ void main() async {
var encoded = json.encode(result[0][0]);
return Response.ok(
encoded,
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'text/plain'
},
headers: {...headers, 'Content-Type': 'text/plain'},
);
});
app.get('/fbla-api/logos/<logo>', (Request request, String logoId) {
@ -426,19 +406,13 @@ void main() async {
List<int> content = logo.readAsBytesSync();
return Response.ok(
content,
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'image/png'
},
headers: {...headers, 'Content-Type': 'image/png'},
);
} catch (e) {
print('Error reading logo!');
return Response.notFound(
'logo not found',
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'image/png'
},
headers: {...headers, 'Content-Type': 'image/png'},
);
}
});
@ -470,7 +444,7 @@ void main() async {
}
return Response.ok(
id.toString(),
headers: {'Access-Control-Allow-Origin': '*'},
headers: headers,
);
} on JWTExpiredException {
print('JWT Expired');
@ -480,7 +454,7 @@ void main() async {
return Response.unauthorized(
'unauthorized',
headers: {'Access-Control-Allow-Origin': '*'},
headers: headers,
);
});
app.post('/fbla-api/createlisting', (Request request) async {
@ -505,7 +479,7 @@ void main() async {
return Response.ok(
id.toString(),
headers: {'Access-Control-Allow-Origin': '*'},
headers: headers,
);
} on JWTExpiredException {
print('JWT Expired');
@ -515,7 +489,7 @@ void main() async {
return Response.unauthorized(
'unauthorized',
headers: {'Access-Control-Allow-Origin': '*'},
headers: headers,
);
});
app.post('/fbla-api/deletebusiness', (Request request) async {
@ -538,7 +512,7 @@ void main() async {
return Response.ok(
id.toString(),
headers: {'Access-Control-Allow-Origin': '*'},
headers: headers,
);
} on JWTExpiredException {
print('JWT Expired');
@ -548,7 +522,7 @@ void main() async {
return Response.unauthorized(
'unauthorized',
headers: {'Access-Control-Allow-Origin': '*'},
headers: headers,
);
});
app.post('/fbla-api/deletelisting', (Request request) async {
@ -565,7 +539,7 @@ void main() async {
return Response.ok(
id.toString(),
headers: {'Access-Control-Allow-Origin': '*'},
headers: headers,
);
} on JWTExpiredException {
print('JWT Expired');
@ -575,7 +549,7 @@ void main() async {
return Response.unauthorized(
'unauthorized',
headers: {'Access-Control-Allow-Origin': '*'},
headers: headers,
);
});
app.post('/fbla-api/editbusiness', (Request request) async {
@ -612,7 +586,7 @@ void main() async {
return Response.ok(
business.id.toString(),
headers: {'Access-Control-Allow-Origin': '*'},
headers: headers,
);
} on JWTExpiredException {
print('JWT Expired');
@ -622,7 +596,7 @@ void main() async {
return Response.unauthorized(
'unauthorized',
headers: {'Access-Control-Allow-Origin': '*'},
headers: headers,
);
});
app.post('/fbla-api/editlisting', (Request request) async {
@ -645,7 +619,7 @@ void main() async {
return Response.ok(
listing.id.toString(),
headers: {'Access-Control-Allow-Origin': '*'},
headers: headers,
);
} on JWTExpiredException {
print('JWT Expired');
@ -655,7 +629,7 @@ void main() async {
return Response.unauthorized(
'unauthorized',
headers: {'Access-Control-Allow-Origin': '*'},
headers: headers,
);
});
app.post('/fbla-api/signin', (Request request) async {
@ -671,7 +645,7 @@ void main() async {
if (saltDb.isEmpty) {
return Response.unauthorized(
'invalid username',
headers: {'Access-Control-Allow-Origin': '*'},
headers: headers,
);
}
@ -712,12 +686,12 @@ void main() async {
return Response.ok(
token.toString(),
headers: {'Access-Control-Allow-Origin': '*'},
headers: headers,
);
} else {
return Response.unauthorized(
'invalid password',
headers: {'Access-Control-Allow-Origin': '*'},
headers: headers,
);
}
});
@ -761,7 +735,7 @@ void main() async {
return Response.ok(
username,
headers: {'Access-Control-Allow-Origin': '*'},
headers: headers,
);
} on JWTExpiredException {
print('JWT Expired');
@ -771,7 +745,7 @@ void main() async {
return Response.unauthorized(
'unauthorized',
headers: {'Access-Control-Allow-Origin': '*'},
headers: headers,
);
});
app.post('/fbla-api/deleteuser', (Request request) async {
@ -793,7 +767,7 @@ void main() async {
return Response.ok(
username,
headers: {'Access-Control-Allow-Origin': '*'},
headers: headers,
);
} on JWTExpiredException {
print('JWT Expired');
@ -803,7 +777,7 @@ void main() async {
return Response.unauthorized(
'unauthorized',
headers: {'Access-Control-Allow-Origin': '*'},
headers: headers,
);
});
app.get('/fbla-api/marinodev', (Request request) async {
@ -814,10 +788,7 @@ void main() async {
return Response.ok(
content,
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'image/svg+xml'
},
headers: {...headers, 'Content-Type': 'image/svg+xml'},
);
});