-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add allow CORS to /api fetch only routes
- Loading branch information
Showing
7 changed files
with
207 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ | |
.pub-cache/ | ||
.pub/ | ||
/build/ | ||
.pubspec.lock | ||
pubspec.lock | ||
|
||
# Environments | ||
.env | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
FROM python:3.9-slim-buster | ||
|
||
ENV AUDIT_WEBHOOK="" | ||
ENV DISCORD_CLIENT_ID=00000000000 | ||
ENV DISCORD_CLIENT_SECRET="your_discord_client_secret" | ||
ENV DISCORD_REDIRECT_URI="https://piracy.moe/user/callback/" | ||
ENV DISCORD_BOT_TOKEN="your_discord_bot_token" | ||
|
||
VOLUME ["/config"] | ||
EXPOSE 8080 | ||
HEALTHCHECK CMD curl --fail http://localhost:8080 || exit 1 | ||
|
||
LABEL org.opencontainers.image.vendor="/r/animepiracy" \ | ||
org.opencontainers.image.url="https://piracy.moe" \ | ||
org.opencontainers.image.description="Webserver of piracy.moe Index" \ | ||
org.opencontainers.image.title="Index" \ | ||
maintainer="Community of /r/animepiracy" | ||
|
||
# copy python requirements beforehand for improved building caching | ||
COPY api/requirements.txt . | ||
|
||
# install nginx and needed python packages | ||
RUN apt-get update -y && \ | ||
apt-get install --no-install-recommends -y nginx makepasswd wget && \ | ||
apt-get autoremove -y && \ | ||
rm -rf /var/lib/apt/lists/* && \ | ||
pip install --no-cache-dir -r requirements.txt | ||
|
||
# replace default nginx conf | ||
COPY nginx.conf /etc/nginx/conf.d/default.conf | ||
|
||
WORKDIR /app | ||
COPY api . | ||
|
||
# sed is for replacing windows newline | ||
CMD sed -i 's/\r$//' start.sh && sh start.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:http/http.dart' as http; | ||
|
||
// for debugging only, on prod everything will be relative, meaning domain = "" | ||
var domain = "http://localhost:8080"; | ||
|
||
class Tab { | ||
final int id; | ||
String name; | ||
String description; | ||
List<int> tables; | ||
|
||
Tab(this.id, this.name, this.description); | ||
|
||
factory Tab.fromJson(Map<String, dynamic> json) { | ||
return Tab(json["id"], json["name"], json["description"]); | ||
} | ||
|
||
static Future<Tab> fetch(int id) async { | ||
return http.get(Uri.parse(domain + '/api/tabs/' + id.toString())).then( | ||
(resp) { | ||
if (resp.statusCode == 200) { | ||
return Tab.fromJson(jsonDecode(resp.body)); | ||
} | ||
throw Exception('Failed to load Tab'); | ||
}, | ||
onError: (e) { | ||
print('Request failed: $e'); | ||
}, | ||
); | ||
} | ||
} | ||
|
||
class Table { | ||
final int id; | ||
String name; | ||
String description; | ||
int tabId; | ||
|
||
// data should be fetched via /api/tables/<id>/data | ||
List<int> data; | ||
|
||
// columns should be fetched via /api/tables/<id>/columns | ||
List<int> columns; | ||
|
||
Table({ | ||
this.id, | ||
this.name, | ||
this.description, | ||
this.tabId, | ||
this.data, | ||
this.columns, | ||
}); | ||
|
||
factory Table.fromJson(Map<String, dynamic> json) { | ||
return Table( | ||
id: json["id"], | ||
name: json["name"], | ||
description: json["description"], | ||
tabId: json["tab_id"], | ||
data: json["data"], | ||
columns: json["columns"], | ||
); | ||
} | ||
|
||
static Future<Table> fetch(int id) async { | ||
return http.get(Uri.parse(domain + '/api/tables/' + id.toString())).then( | ||
(resp) { | ||
if (resp.statusCode == 200) { | ||
return Table.fromJson(jsonDecode(resp.body)); | ||
} | ||
throw Exception('Failed to load Table'); | ||
}, | ||
onError: (e) { | ||
print('Request failed: $e'); | ||
}, | ||
); | ||
} | ||
} | ||
|
||
class Column { | ||
final int id; | ||
String name; | ||
String description; | ||
String columnType; | ||
|
||
Column({this.id, this.name, this.description, this.columnType}); | ||
|
||
factory Column.fromJson(Map<String, dynamic> json) { | ||
return Column( | ||
id: json["id"], | ||
name: json["name"], | ||
description: json["description"], | ||
columnType: json["column_type"], | ||
); | ||
} | ||
|
||
static Future<Column> fetch(int id) async { | ||
return http.get(Uri.parse(domain + '/api/columns/' + id.toString())).then( | ||
(resp) { | ||
if (resp.statusCode == 200) { | ||
return Column.fromJson(jsonDecode(resp.body)); | ||
} | ||
throw Exception('Failed to load Column'); | ||
}, | ||
onError: (e) { | ||
print('Request failed: $e'); | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters