Skip to content

Commit 71ca6d9

Browse files
committed
Get rid of custom server for next.js
1 parent b64a007 commit 71ca6d9

File tree

6 files changed

+25
-51
lines changed

6 files changed

+25
-51
lines changed

packages/skin-database/api/app.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ declare global {
4949
notify(action: ApiAction): void;
5050
log(message: string): void;
5151
logError(message: string): void;
52-
startTime: number;
5352
session: {
5453
username: string | undefined;
5554
};
@@ -69,11 +68,6 @@ export function createApp({ eventHandler, logger, extraMiddleware }: Options) {
6968
app.use(Sentry.Handlers.requestHandler() as RequestHandler);
7069
}
7170

72-
app.use(function (req, res, next) {
73-
req.startTime = Date.now();
74-
next();
75-
});
76-
7771
// https://expressjs.com/en/guide/behind-proxies.html
7872
// This is needed in order to allow `cookieSession({secure: true})` cookies to be sent.
7973
app.set("trust proxy", "loopback");

packages/skin-database/app/graphql/route.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
import { createYoga } from "graphql-yoga";
1+
import { createYoga, YogaInitialContext } from "graphql-yoga";
22
import { getSchema } from "../../api/graphql/schema";
3+
import UserContext from "../../data/UserContext";
4+
import DiscordEventHandler from "../../api/DiscordEventHandler";
5+
6+
const handler = new DiscordEventHandler();
37

48
interface NextContext {
59
params: Promise<Record<string, string>>;
@@ -21,6 +25,23 @@ const { handleRequest } = createYoga<NextContext>({
2125
methods: ["GET", "POST", "OPTIONS"],
2226
credentials: true,
2327
},
28+
context: (ctx: YogaInitialContext) => {
29+
return {
30+
...ctx.request,
31+
ctx: new UserContext(),
32+
notify: (action) => handler.handle(action),
33+
log(message: string) {
34+
console.log(message, {
35+
url: ctx.request.url,
36+
});
37+
},
38+
error(message: string) {
39+
console.error(message, {
40+
url: ctx.request.url,
41+
});
42+
},
43+
};
44+
},
2445
});
2546

2647
export {

packages/skin-database/knexfile.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ const configs = {
2626
},
2727
development: {
2828
...production,
29-
connection: {
30-
...production.connection,
31-
filename: path.join(__dirname, "./skins-dev.sqlite3"),
32-
},
3329
},
3430
production,
3531
};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** @type {import('next').NextConfig} */
22
const nextConfig = {
3-
serverExternalPackages: ["knex", "imagemin-optipng"],
3+
serverExternalPackages: ["knex", "imagemin-optipng", "discord.js"],
44
};
55

66
module.exports = nextConfig;

packages/skin-database/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@
5555
"sync": "ts-node --transpile-only ./tasks/syncWithArchive.ts",
5656
"migrate": "knex migrate:latest",
5757
"grats": "grats",
58-
"dev:next": "ts-node --transpile-only server.ts",
58+
"dev:next": "next dev",
5959
"build:next": "next build",
60-
"start:next": "NODE_ENV=production ts-node --transpile-only server.ts",
60+
"start:next": "next start",
6161
"lint:next": "next lint"
6262
},
6363
"prettier": {},

packages/skin-database/server.ts

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

0 commit comments

Comments
 (0)