Skip to content

Commit e8c677d

Browse files
committed
Remove express in favor of next.js
1 parent 77e022a commit e8c677d

File tree

13 files changed

+161
-491
lines changed

13 files changed

+161
-491
lines changed

packages/skin-database/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ The discord bot allows us to:
1717
## Server
1818

1919
This package also includes a GraphQL interface for exploring skins. It is not currently used by anything, but can be useful for inspecting the data.
20+
sudo systemctl reload apache2

packages/skin-database/api/DiscordEventHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ApiAction } from "./app";
1+
import { ApiAction } from "./types";
22
import Discord, { TextChannel } from "discord.js";
33
import * as Config from "../config";
44
import SkinModel from "../data/SkinModel";

packages/skin-database/api/__tests__/graphql.test.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
import { Application } from "express";
21
import { knex } from "../../db";
3-
import request from "supertest"; // supertest is a framework that allows to easily test web apis
4-
import { createApp } from "../app";
52
import SkinModel from "../../data/SkinModel";
63
import * as S3 from "../../s3";
74
import { processUserUploads } from "../processUserUploads";
85
import UserContext from "../../data/UserContext";
96
import { searchIndex } from "../../algolia";
7+
import { createYogaInstance } from "../../app/graphql/yoga";
8+
import { YogaServerInstance } from "graphql-yoga";
109
jest.mock("../../s3");
1110
jest.mock("../../algolia");
1211
jest.mock("../processUserUploads");
1312
jest.mock("../auth");
1413

15-
let app: Application;
14+
let yoga: YogaServerInstance<any, any>;
1615
const handler = jest.fn();
1716
const log = jest.fn();
1817
const logError = jest.fn();
@@ -22,12 +21,9 @@ let username: string | undefined;
2221
beforeEach(async () => {
2322
jest.clearAllMocks();
2423
username = "<MOCKED>";
25-
app = createApp({
24+
yoga = createYogaInstance({
2625
eventHandler: handler,
27-
extraMiddleware: (req, res, next) => {
28-
req.session.username = username;
29-
next();
30-
},
26+
getUserContext: () => new UserContext(username),
3127
logger: { log, logError },
3228
});
3329
await knex.migrate.latest();
@@ -39,9 +35,12 @@ function gql(templateString: TemplateStringsArray): string {
3935
}
4036

4137
async function graphQLRequest(query: string, variables?: any) {
42-
const { body } = await request(app)
43-
.post("/graphql")
44-
.send({ query, variables: variables ?? {} });
38+
const response = await yoga.fetch("/graphql", {
39+
method: "POST",
40+
headers: { "Content-Type": "application/json" },
41+
body: JSON.stringify({ query, variables }),
42+
});
43+
const body = await response.json();
4544
if (body.errors && body.errors.length) {
4645
for (const err of body.errors) {
4746
console.warn(err.message);

packages/skin-database/api/app.ts

Lines changed: 0 additions & 191 deletions
This file was deleted.

packages/skin-database/api/processUserUploads.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as Skins from "../data/skins";
22
import S3 from "../s3";
33
import { addSkinFromBuffer } from "../addSkin";
4-
import { EventHandler } from "./app";
4+
import { EventHandler } from "./types";
55
import DiscordEventHandler from "./DiscordEventHandler";
66

77
async function* reportedUploads(): AsyncGenerator<

packages/skin-database/api/server.ts

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import UserContext from "../data/UserContext";
2+
3+
export type ApiAction =
4+
| { type: "REVIEW_REQUESTED"; md5: string }
5+
| { type: "REJECTED_SKIN"; md5: string }
6+
| { type: "APPROVED_SKIN"; md5: string }
7+
| { type: "MARKED_SKIN_NSFW"; md5: string }
8+
| { type: "SKIN_UPLOADED"; md5: string }
9+
| { type: "ERROR_PROCESSING_UPLOAD"; id: string; message: string }
10+
| { type: "CLASSIC_SKIN_UPLOADED"; md5: string }
11+
| { type: "MODERN_SKIN_UPLOADED"; md5: string }
12+
| { type: "SKIN_UPLOAD_ERROR"; uploadId: string; message: string }
13+
| {
14+
type: "GOT_FEEDBACK";
15+
message: string;
16+
email?: string | null;
17+
url?: string | null;
18+
}
19+
| {
20+
type: "SYNCED_TO_ARCHIVE";
21+
successes: number;
22+
errors: number;
23+
skips: number;
24+
}
25+
| { type: "STARTED_SYNC_TO_ARCHIVE"; count: number }
26+
| {
27+
type: "POPULAR_TWEET";
28+
bracket: number;
29+
url: string;
30+
likes: number;
31+
date: Date;
32+
}
33+
| { type: "TWEET_BOT_MILESTONE"; bracket: number; count: number };
34+
35+
export type EventHandler = (event: ApiAction) => void;
36+
export type Logger = {
37+
log(message: string, context: any): void;
38+
logError(message: string, context: any): void;
39+
};
40+
41+
// Add UserContext to req objects globally
42+
declare global {
43+
namespace Express {
44+
interface Request {
45+
ctx: UserContext;
46+
notify(action: ApiAction): void;
47+
log(message: string): void;
48+
logError(message: string): void;
49+
session: {
50+
username: string | undefined;
51+
};
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)