1
0
Fork 0
forked from OpenNeo/impress

Optionally use local instance of impress-2020 during development

To activate this, I created a `.env.development` file in my project
root, with the following content:

```env
IMPRESS_2020_ORIGIN=http://localhost:4000
```

Then, I started impress-2020 with `yarn dev --port=4000`.

Now, the app loads from there, hooray!! It even fixes that obnoxious
pet state ID bug that happens when you run against the production db lol
This commit is contained in:
Emi Matchu 2024-01-28 07:00:29 -08:00
parent 4eb4013eb2
commit 6763e9454e
10 changed files with 31 additions and 6 deletions

View file

@ -87,6 +87,11 @@ module ApplicationHelper
!@hide_home_link !@hide_home_link
end end
def impress_2020_meta_tag
tag 'meta', name: "impress-2020-origin",
content: Rails.configuration.impress_2020_origin
end
JAVASCRIPT_LIBRARIES = { JAVASCRIPT_LIBRARIES = {
:jquery => 'https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js', :jquery => 'https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js',
:jquery20 => 'https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js', :jquery20 => 'https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js',

View file

@ -629,7 +629,7 @@ export function buildOutfitUrl(outfitState, options = {}) {
const origin = const origin =
typeof window !== "undefined" typeof window !== "undefined"
? window.location.origin ? window.location.origin
: "https://impress-2020.openneo.net"; : "https://impress.openneo.net";
return origin + buildOutfitPath(outfitState, options); return origin + buildOutfitPath(outfitState, options);
} }

View file

@ -2,6 +2,8 @@ import { ApolloClient, createHttpLink, InMemoryCache } from "@apollo/client";
import { loadErrorMessages, loadDevMessages } from "@apollo/client/dev"; import { loadErrorMessages, loadDevMessages } from "@apollo/client/dev";
import { createPersistedQueryLink } from "apollo-link-persisted-queries"; import { createPersistedQueryLink } from "apollo-link-persisted-queries";
import { buildImpress2020Url } from "./impress-2020-config";
// Use Apollo's error messages in development. // Use Apollo's error messages in development.
if (process.env["NODE_ENV"] === "development") { if (process.env["NODE_ENV"] === "development") {
loadErrorMessages(); loadErrorMessages();
@ -159,7 +161,7 @@ const typePolicies = {
const cache = new InMemoryCache({ typePolicies }); const cache = new InMemoryCache({ typePolicies });
const httpLink = createHttpLink({ const httpLink = createHttpLink({
uri: "https://impress-2020.openneo.net/api/graphql", uri: buildImpress2020Url("/api/graphql"),
}); });
const link = createPersistedQueryLink({ const link = createPersistedQueryLink({

View file

@ -3,6 +3,7 @@ import gql from "graphql-tag";
import { useQuery } from "@apollo/client"; import { useQuery } from "@apollo/client";
import { Box, Flex, Select, Text, useColorModeValue } from "@chakra-ui/react"; import { Box, Flex, Select, Text, useColorModeValue } from "@chakra-ui/react";
import { buildImpress2020Url } from "../impress-2020-config";
import { Delay, logAndCapture, useFetch } from "../util"; import { Delay, logAndCapture, useFetch } from "../util";
/** /**
@ -346,7 +347,7 @@ let cachedResponseForAllValidPetPoses = null;
*/ */
export function useAllValidPetPoses() { export function useAllValidPetPoses() {
const networkResponse = useFetch( const networkResponse = useFetch(
"https://impress-2020.openneo.net/api/validPetPoses", buildImpress2020Url("/api/validPetPoses"),
{ {
responseType: "arrayBuffer", responseType: "arrayBuffer",
// If we already have globally-cached valids, skip the request. // If we already have globally-cached valids, skip the request.

View file

@ -0,0 +1,10 @@
const IMPRESS_2020_ORIGIN = readImpress2020Origin();
export function buildImpress2020Url(path) {
return new URL(path, IMPRESS_2020_ORIGIN).toString();
}
function readImpress2020Origin() {
const node = document.querySelector("meta[name=impress-2020-origin]");
return node?.content || "https://impress-2020.openneo.net"
}

View file

@ -11,6 +11,8 @@ import loadableLibrary from "@loadable/component";
import * as Sentry from "@sentry/react"; import * as Sentry from "@sentry/react";
import { WarningIcon } from "@chakra-ui/icons"; import { WarningIcon } from "@chakra-ui/icons";
import { buildImpress2020Url } from "./impress-2020-config";
import ErrorGrundoImg from "./images/error-grundo.png"; import ErrorGrundoImg from "./images/error-grundo.png";
import ErrorGrundoImg2x from "./images/error-grundo@2x.png"; import ErrorGrundoImg2x from "./images/error-grundo@2x.png";
@ -141,7 +143,7 @@ export function safeImageUrl(
`safeImageUrl could not parse URL: ${urlString}. Returning a placeholder.`, `safeImageUrl could not parse URL: ${urlString}. Returning a placeholder.`,
), ),
); );
return "https://impress-2020.openneo.net/__error__URL-was-not-parseable__"; return buildImpress2020Url("/__error__URL-was-not-parseable__");
} }
// Rewrite Neopets URLs to their HTTPS equivalents, and additionally to our // Rewrite Neopets URLs to their HTTPS equivalents, and additionally to our
@ -178,7 +180,7 @@ export function safeImageUrl(
`upgrade it to HTTPS: ${urlString}. Returning a placeholder.`, `upgrade it to HTTPS: ${urlString}. Returning a placeholder.`,
), ),
); );
return "https://impress-2020.openneo.net/__error__URL-was-not-HTTPS__"; return buildImpress2020Url("/__error__URL-was-not-HTTPS__");
} }
return url.toString(); return url.toString();

View file

@ -17,6 +17,7 @@
= yield :meta = yield :meta
= open_graph_tags = open_graph_tags
= csrf_meta_tag = csrf_meta_tag
= impress_2020_meta_tag
= signed_in_meta_tag = signed_in_meta_tag
- if user_signed_in? - if user_signed_in?
= current_user_id_meta_tag = current_user_id_meta_tag

View file

@ -20,6 +20,7 @@
= render 'static/analytics' = render 'static/analytics'
= open_graph_tags = open_graph_tags
= csrf_meta_tags = csrf_meta_tags
= impress_2020_meta_tag
%meta{name: 'dti-current-user-id', content: user_signed_in? ? current_user.id : "null"} %meta{name: 'dti-current-user-id', content: user_signed_in? ? current_user.id : "null"}
%body %body
#wardrobe-2020-root #wardrobe-2020-root

View file

@ -0,0 +1,2 @@
Rails.configuration.impress_2020_origin =
ENV["IMPRESS_2020_ORIGIN"] || "https://impress-2020.openneo.net"

View file

@ -87,7 +87,8 @@ OpenneoImpressItems::Application.routes.draw do
get '/donate' => 'campaigns#current', as: :donate get '/donate' => 'campaigns#current', as: :donate
# Static pages! # Static pages!
get '/terms' => redirect("https://impress-2020.openneo.net/terms"), :as => :terms get '/terms', as: :terms,
to: redirect(Rails.configuration.impress_2020_origin + "/terms")
# Other useful lil things! # Other useful lil things!
get '/sitemap.xml' => 'sitemap#index', :as => :sitemap, :format => :xml get '/sitemap.xml' => 'sitemap#index', :as => :sitemap, :format => :xml