From 8dab44292911f3606a701db299b0fd699a2b8e01 Mon Sep 17 00:00:00 2001 From: Matchu Date: Mon, 1 Nov 2021 22:25:43 -0700 Subject: [PATCH] [WIP] API routes working for Next.js Things seemed to mostly work at first glance! I haven't tested outfitPageSSR because we'll need to redo it though, and also the outfit image routes aren't working anymore (vercel.json isn't how next.js works) --- {api => pages/api}/allWakaValues.js | 2 +- {api => pages/api}/assetImage.js | 0 {api => pages/api}/graphql.js | 4 ++-- {api => pages/api}/outfitImage.js | 6 +++--- {api => pages/api}/outfitPageSSR.js | 4 ++-- {api => pages/api}/sendFeedback.js | 0 {api => pages/api}/uploadLayerImage.js | 6 +++--- {api => pages/api}/validPetPoses.js | 4 ++-- 8 files changed, 13 insertions(+), 13 deletions(-) rename {api => pages/api}/allWakaValues.js (98%) rename {api => pages/api}/assetImage.js (100%) rename {api => pages/api}/graphql.js (95%) rename {api => pages/api}/outfitImage.js (98%) rename {api => pages/api}/outfitPageSSR.js (98%) rename {api => pages/api}/sendFeedback.js (100%) rename {api => pages/api}/uploadLayerImage.js (97%) rename {api => pages/api}/validPetPoses.js (96%) diff --git a/api/allWakaValues.js b/pages/api/allWakaValues.js similarity index 98% rename from api/allWakaValues.js rename to pages/api/allWakaValues.js index ecf9f21..1b4dcc6 100644 --- a/api/allWakaValues.js +++ b/pages/api/allWakaValues.js @@ -10,7 +10,7 @@ const beeline = require("honeycomb-beeline")({ import fetch from "node-fetch"; -import connectToDb from "../src/server/db"; +import connectToDb from "../../src/server/db"; async function handle(req, res) { const allNcItemNamesAndIdsPromise = loadAllNcItemNamesAndIds(); diff --git a/api/assetImage.js b/pages/api/assetImage.js similarity index 100% rename from api/assetImage.js rename to pages/api/assetImage.js diff --git a/api/graphql.js b/pages/api/graphql.js similarity index 95% rename from api/graphql.js rename to pages/api/graphql.js index cd2e2bf..d23fe3c 100644 --- a/api/graphql.js +++ b/pages/api/graphql.js @@ -9,8 +9,8 @@ const beeline = require("honeycomb-beeline")({ samplerHook, }); -const { ApolloServer } = require("../src/server/lib/apollo-server-vercel"); -const { config } = require("../src/server"); +const { ApolloServer } = require("../../src/server/lib/apollo-server-vercel"); +const { config } = require("../../src/server"); const crypto = require("crypto"); const server = new ApolloServer(config); diff --git a/api/outfitImage.js b/pages/api/outfitImage.js similarity index 98% rename from api/outfitImage.js rename to pages/api/outfitImage.js index 8f3275b..4904757 100644 --- a/api/outfitImage.js +++ b/pages/api/outfitImage.js @@ -39,12 +39,12 @@ import fetch from "node-fetch"; import gql from "graphql-tag"; import { print as graphqlPrint } from "graphql/language/printer"; -import connectToDb from "../src/server/db"; -import { renderOutfitImage } from "../src/server/outfit-images"; +import connectToDb from "../../src/server/db"; +import { renderOutfitImage } from "../../src/server/outfit-images"; import getVisibleLayers, { petAppearanceFragmentForGetVisibleLayers, itemAppearanceFragmentForGetVisibleLayers, -} from "../src/shared/getVisibleLayers"; +} from "../../src/shared/getVisibleLayers"; const VALID_LAYER_URLS = [ /^https:\/\/(impress-asset-images\.openneo\.net|impress-asset-images\.s3\.amazonaws\.com)\/(biology|object)\/[0-9]{3}\/[0-9]{3}\/[0-9]{3}\/[0-9]+\/(150|300|600)x(150|300|600)\.png(\?[a-zA-Z0-9_-]+)?$/, diff --git a/api/outfitPageSSR.js b/pages/api/outfitPageSSR.js similarity index 98% rename from api/outfitPageSSR.js rename to pages/api/outfitPageSSR.js index 861370d..d34bd74 100644 --- a/api/outfitPageSSR.js +++ b/pages/api/outfitPageSSR.js @@ -25,8 +25,8 @@ const beeline = require("honeycomb-beeline")({ import escapeHtml from "escape-html"; import fetch from "node-fetch"; -import connectToDb from "../src/server/db"; -import { normalizeRow } from "../src/server/util"; +import connectToDb from "../../src/server/db"; +import { normalizeRow } from "../../src/server/util"; async function handle(req, res) { // Load index.html as our initial page content. If this fails, it probably diff --git a/api/sendFeedback.js b/pages/api/sendFeedback.js similarity index 100% rename from api/sendFeedback.js rename to pages/api/sendFeedback.js diff --git a/api/uploadLayerImage.js b/pages/api/uploadLayerImage.js similarity index 97% rename from api/uploadLayerImage.js rename to pages/api/uploadLayerImage.js index 01669f6..035691b 100644 --- a/api/uploadLayerImage.js +++ b/pages/api/uploadLayerImage.js @@ -10,13 +10,13 @@ const beeline = require("honeycomb-beeline")({ const AWS = require("aws-sdk"); const Jimp = require("jimp"); -const connectToDb = require("../src/server/db"); -const buildLoaders = require("../src/server/loaders"); +const connectToDb = require("../../src/server/db"); +const buildLoaders = require("../../src/server/loaders"); const { loadBodyName, logToDiscord, normalizeRow, -} = require("../src/server/util"); +} = require("../../src/server/util"); if ( !process.env["DTI_AWS_ACCESS_KEY_ID"] || diff --git a/api/validPetPoses.js b/pages/api/validPetPoses.js similarity index 96% rename from api/validPetPoses.js rename to pages/api/validPetPoses.js index be479b4..641022f 100644 --- a/api/validPetPoses.js +++ b/pages/api/validPetPoses.js @@ -7,8 +7,8 @@ const beeline = require("honeycomb-beeline")({ serviceName: "impress-2020-gql-server", disableInstrumentationOnLoad: true, }); -import connectToDb from "../src/server/db"; -import { getPoseFromPetState, normalizeRow } from "../src/server/util"; +import connectToDb from "../../src/server/db"; +import { getPoseFromPetState, normalizeRow } from "../../src/server/util"; export async function getValidPetPoses() { const db = await connectToDb();