Skip to content

Commit

Permalink
Chore route cleanup (#63)
Browse files Browse the repository at this point in the history
* route cleanup

* Few missed routes

---------

Co-authored-by: Brandon R <[email protected]>
Co-authored-by: Brandon Roberts <[email protected]>
  • Loading branch information
3 people authored Apr 26, 2024
1 parent f32dba2 commit 8d44c71
Show file tree
Hide file tree
Showing 17 changed files with 33 additions and 54 deletions.
4 changes: 2 additions & 2 deletions backend/routes/canvas.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
)

func InitCanvasRoutes() {
http.HandleFunc("/initCanvas", initCanvas)
http.HandleFunc("/getCanvas", getCanvas)
http.HandleFunc("/init-canvas", initCanvas)
http.HandleFunc("/get-canvas", getCanvas)
}

func initCanvas(w http.ResponseWriter, r *http.Request) {
Expand Down
4 changes: 2 additions & 2 deletions backend/routes/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
)

func InitContractRoutes() {
http.HandleFunc("/getContractAddress", getContractAddress)
http.HandleFunc("/setContractAddress", setContractAddress)
http.HandleFunc("/get-contract-address", getContractAddress)
http.HandleFunc("/set-contract-address", setContractAddress)
}

func getContractAddress(w http.ResponseWriter, r *http.Request) {
Expand Down
2 changes: 1 addition & 1 deletion backend/routes/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
)

func InitIndexerRoutes() {
http.HandleFunc("/consumeIndexerMsg", consumeIndexerMsg)
http.HandleFunc("/consume-indexer-msg", consumeIndexerMsg)
}

// TODO: Clean up
Expand Down
21 changes: 0 additions & 21 deletions backend/routes/nft.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ func InitNFTRoutes() {
http.HandleFunc("/mint-nft-devnet", mintNFTDevnet)
// Create a static file server for the nft images
http.Handle("/nft-images/", http.StripPrefix("/nft-images/", http.FileServer(http.Dir("."))))
//http.HandleFunc("/nft-image", nftImage)
}

type NFTData struct {
Expand Down Expand Up @@ -136,26 +135,6 @@ func getNFTs(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(out))
}

// func nftImage(w http.ResponseWriter, r *http.Request) {
// // Get the png image at location "nft-{tokenId}.png"
// tokenId := r.URL.Query().Get("tokenId")
// imageLocation := fmt.Sprintf("nft-%s.png", tokenId)
//
// image, err := os.Open(imageLocation)
// if err != nil {
// w.WriteHeader(http.StatusInternalServerError)
// w.Write([]byte(err.Error()))
// return
// }
// defer image.Close()
//
// w.Header().Set("Access-Control-Allow-Origin", "*")
// w.Header().Set("Content-Type", "image/png")
// w.WriteHeader(http.StatusOK)
//
// io.Copy(w, image)
// }

func mintNFTDevnet(w http.ResponseWriter, r *http.Request) {
reqBody, err := io.ReadAll(r.Body)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions backend/routes/pixel.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import (
)

func InitPixelRoutes() {
http.HandleFunc("/getPixel", getPixel)
http.HandleFunc("/getPixelInfo", getPixelInfo)
http.HandleFunc("/get-pixel", getPixel)
http.HandleFunc("/get-pixel-info", getPixelInfo)
if !core.ArtPeaceBackend.BackendConfig.Production {
http.HandleFunc("/placePixelDevnet", placePixelDevnet)
http.HandleFunc("/placeExtraPixelsDevnet", placeExtraPixelsDevnet)
http.HandleFunc("/place-pixel-devnet", placePixelDevnet)
http.HandleFunc("/place-extra-pixels-devnet", placeExtraPixelsDevnet)
}
http.HandleFunc("/placePixelRedis", placePixelRedis)
http.HandleFunc("/place-pixel-redis", placePixelRedis)
}

func getPixel(w http.ResponseWriter, r *http.Request) {
Expand Down
4 changes: 2 additions & 2 deletions backend/routes/quests.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ type Quest struct {
}

func InitQuestsRoutes() {
http.HandleFunc("/getDailyQuests", GetDailyQuests)
http.HandleFunc("/getMainQuests", GetMainQuests)
http.HandleFunc("/get-daily-duests", GetDailyQuests)
http.HandleFunc("/get-main-quests", GetMainQuests)
}

// Query dailyQuests
Expand Down
4 changes: 2 additions & 2 deletions backend/routes/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import (

func InitTemplateRoutes() {
http.HandleFunc("/get-templates", getTemplates)
http.HandleFunc("/addTemplateImg", addTemplateImg)
http.HandleFunc("/add-template-img", addTemplateImg)
http.HandleFunc("/add-template-data", addTemplateData)
http.Handle("/templates/", http.StripPrefix("/templates/", http.FileServer(http.Dir("."))))
if !core.ArtPeaceBackend.BackendConfig.Production {
http.HandleFunc("/add-template-devnet", addTemplateDevnet)
}
http.Handle("/templates/", http.StripPrefix("/templates/", http.FileServer(http.Dir("."))))
}

// TODO: Add specific location for template images
Expand Down
6 changes: 3 additions & 3 deletions backend/routes/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
)

func InitUserRoutes() {
http.HandleFunc("/getExtraPixels", getExtraPixels)
http.HandleFunc("/getUsername", getUsername)
http.HandleFunc("/getPixelCount", getPixelCount)
http.HandleFunc("/get-extra-pixels", getExtraPixels)
http.HandleFunc("/get-username", getUsername)
http.HandleFunc("/get-pixel-count", getPixelCount)
}

func setCommonHeaders(w http.ResponseWriter) {
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ services:
- apibara
environment:
- APIBARA_STREAM_URL=http://art-peace-apibara-1:7171
- BACKEND_TARGET_URL=http://art-peace-backend-1:8080/consumeIndexerMsg
- BACKEND_TARGET_URL=http://art-peace-backend-1:8080/consume-indexer-msg
volumes:
- configs:/configs
restart: on-failure
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function App() {

useEffect(() => {
const address = 0;
let getExtraPixelsEndpoint = `${backendUrl}/getExtraPixels?address=${address}`;
let getExtraPixelsEndpoint = `${backendUrl}/get-extra-pixels?address=${address}`;
fetch(getExtraPixelsEndpoint, { mode: "cors" }).then((response) => {
response
.json()
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/canvas/Canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const Canvas = props => {
const canvas = props.canvasRef.current
const context = canvas.getContext('2d')

let getCanvasEndpoint = backendUrl + "/getCanvas"
let getCanvasEndpoint = backendUrl + "/get-canvas"
fetch(getCanvasEndpoint, { mode: 'cors' }).then(response => {
return response.arrayBuffer()
}).then(data => {
Expand Down Expand Up @@ -216,7 +216,7 @@ const Canvas = props => {

const position = y * width + x;
let getPixelInfoEndpoint =
backendUrl + "/getPixelInfo?position=" + position.toString();
backendUrl + "/get-pixel-info?position=" + position.toString();
fetch(getPixelInfoEndpoint, {
mode: "cors",
})
Expand Down Expand Up @@ -360,7 +360,7 @@ const Canvas = props => {

const position = props.selectedPositionX + props.selectedPositionY * width
const colorIdx = props.selectedColorId
let placePixelEndpoint = backendUrl + "/placePixelDevnet"
let placePixelEndpoint = backendUrl + "/place-pixel-devnet"

fetch(placePixelEndpoint, {
mode: "cors",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/canvas/ExtraPixelsPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const ExtraPixelsPanel = props => {
}

const submit = () => {
let placeExtraPixelsEndpoint = backendUrl + "/placeExtraPixelsDevnet";
let placeExtraPixelsEndpoint = backendUrl + "/place-extra-pixels-devnet";
fetch(placeExtraPixelsEndpoint, {
mode: "cors",
method: "POST",
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/tabs/Account.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const Account = (props) => {
};

useEffect(() => {
const getUsernameUrl = `${backendUrl}/getUsername?address=${userAddress}`;
const getUsernameUrl = `${backendUrl}/get-username?address=${userAddress}`;
fetch(getUsernameUrl, {mode: "cors"})
.then(res => {
if (!res.ok) {
Expand All @@ -49,7 +49,7 @@ const Account = (props) => {

useEffect(() => {
const fetchPixelCount = async () => {
const getPixelCountUrl = `${backendUrl}/getPixelCount?address=${userAddress}`;
const getPixelCountUrl = `${backendUrl}/get-pixel-count?address=${userAddress}`;
const response = await fetch(getPixelCountUrl, {mode: "cors"});
if (response.ok) {
const data = await response.json();
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/tabs/quests/Quests.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ const Quests = (props) => {
const fetchQuests = async () => {
try {
// Fetching daily quests from backend
const dailyResponse = await fetch('http://localhost:8080/getDailyQuests');
const dailyResponse = await fetch('http://localhost:8080/get-daily-quests');
const dailyData = await dailyResponse.json();
setDailyQuests(dailyData);

// Fetching main quests from backend
const mainResponse = await fetch('http://localhost:8080/getMainQuests');
const mainResponse = await fetch('http://localhost:8080/get-main-quests');
const mainData = await mainResponse.json();
setMainQuests(mainData);
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion indexer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ This directory contains the Apibara indexer setup for `art/peace`, which indexes
# Create an indexer.env file with the following :
# ART_PEACE_CONTRACT_ADDRESS=... # Example: 0x78223f7ab13216727ed426380079c169578cafad83a3178c7b33ba7ca307713
# APIBARA_STREAM_URL=... # Example: http://localhost:7171
# BACKEND_TARGET_URL=... # Example: http://localhost:8080/consumeIndexerMsg
# BACKEND_TARGET_URL=... # Example: http://localhost:8080/consume-indexer-msg
apibara run scripts.js --allow-env indexer.env
```
4 changes: 2 additions & 2 deletions tests/integration/docker/initialize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ echo "Deploying the application"
./deploy.sh

echo "Initializing the canvas"
curl http://backend:8080/initCanvas -X POST
curl http://backend:8080/init-canvas -X POST

echo "Set the contract address"
CONTRACT_ADDRESS=$(cat /configs/configs.env | grep "^ART_PEACE_CONTRACT_ADDRESS" | cut -d '=' -f2)
curl http://backend:8080/setContractAddress -X POST -d "$CONTRACT_ADDRESS"
curl http://backend:8080/set-contract-address -X POST -d "$CONTRACT_ADDRESS"

echo "Setup the colors from the color config"
# flatten colors with quotes and join them with comma and wrap in []
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/local/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ touch $TMP_DIR/indexer.env
echo "ART_PEACE_CONTRACT_ADDRESS=$ART_PEACE_CONTRACT_ADDRESS" >> $TMP_DIR/indexer.env
echo "NFT_CONTRACT_ADDRESS=$CANVAS_NFT_CONTRACT_ADDRESS" >> $TMP_DIR/indexer.env
echo "APIBARA_STREAM_URL=http://localhost:7171" >> $TMP_DIR/indexer.env
echo "BACKEND_TARGET_URL=http://localhost:8080/consumeIndexerMsg" >> $TMP_DIR/indexer.env
echo "BACKEND_TARGET_URL=http://localhost:8080/consume-indexer-msg" >> $TMP_DIR/indexer.env
apibara run script.js --allow-env $TMP_DIR/indexer.env 2>&1 > $INDEXER_SCRIPT_LOG_FILE &
INDEXER_SCRIPT_PID=$!
sleep 2 # Wait for indexer script to start; TODO: Check if indexer script is actually running

# Initialize the art-peace canvas in the backend/redis
echo "Initializing art-peace canvas ..."
curl http://localhost:8080/initCanvas -X POST
curl http://localhost:8080/setContractAddress -X POST -d "$ART_PEACE_CONTRACT_ADDRESS"
curl http://localhost:8080/init-canvas -X POST
curl http://localhost:8080/set-contract-address -X POST -d "$ART_PEACE_CONTRACT_ADDRESS"
COLORS=$(cat $CANVAS_CONFIG_FILE | jq -r '.colors | map("\"\(.)\"") | join(",")')
curl http://localhost:8080/init-colors -X POST -d "[$COLORS]"

Expand Down

0 comments on commit 8d44c71

Please sign in to comment.