3arcus
3arcus
Explore posts from servers
RRailway
Created by 3arcus on 5/29/2023 in #✋|help
Cant load my metadata from xpress server due to cors policy
Access to XMLHttpRequest at 'https://metaserver-production.up.railway.app/nfts/0' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. This is a problem, how do I overcome this? Ty
12 replies
RRailway
Created by 3arcus on 5/28/2023 in #✋|help
Simple node express server not serving routes, no errors
very simple server.js file, this is my code, the app runs locally but not on railway, no routes are served
const express = require("express");
const app = express();
const fs = require("fs");
const path = require("path");

app.get("/:key", (req, res) => {
const key = req.params.key;
const filePath = path.join(__dirname, "db.json");
fs.readFile(filePath, (err, data) => {
if (err) {
console.error("Error reading file:", err);
return res.status(500).json({ error: "Internal server error" });
}

let jsonData;
try {
jsonData = JSON.parse(data);
} catch (err) {
console.error("Error parsing JSON:", err);
return res.status(500).json({ error: "Internal server error" });
}

if (!jsonData[key]) {
console.error("Key not found in JSON data:", key);
return res.status(404).json({ error: `Key "${key}" not found in data` });
}

res.json(jsonData[key]);
});
});

app.get("/:key/:id", (req, res) => {
const key = req.params.key;
const id = req.params.id;
const filePath = path.join(__dirname, "db.json");
fs.readFile(filePath, (err, data) => {
if (err) {
console.error(`Error reading file from disk: ${err}`);
return res.status(500).send(`Error reading file from disk: ${err}`);
}
let jsonData;
try {
jsonData = JSON.parse(data);
} catch (parseErr) {
console.error(`Error parsing JSON file: ${parseErr}`);
return res.status(500).send(`Error parsing JSON file: ${parseErr}`);
}

if (!jsonData[key]) {
console.error(`Key "${key}" not found in the JSON data.`);
return res.status(404).send(`Key "${key}" not found in the JSON data.`);
}

const item = jsonData[key].find((item) => item.id === parseInt(id));

if (!item) {
console.error(`Item with id "${id}" not found in the key "${key}".`);
return res
.status(404)
.send(`Item with id "${id}" not found in the key "${key}".`);
}

res.json(item);
});
});

app.listen(3000, () => {
console.log("Server started on port 3000");
});
const express = require("express");
const app = express();
const fs = require("fs");
const path = require("path");

app.get("/:key", (req, res) => {
const key = req.params.key;
const filePath = path.join(__dirname, "db.json");
fs.readFile(filePath, (err, data) => {
if (err) {
console.error("Error reading file:", err);
return res.status(500).json({ error: "Internal server error" });
}

let jsonData;
try {
jsonData = JSON.parse(data);
} catch (err) {
console.error("Error parsing JSON:", err);
return res.status(500).json({ error: "Internal server error" });
}

if (!jsonData[key]) {
console.error("Key not found in JSON data:", key);
return res.status(404).json({ error: `Key "${key}" not found in data` });
}

res.json(jsonData[key]);
});
});

app.get("/:key/:id", (req, res) => {
const key = req.params.key;
const id = req.params.id;
const filePath = path.join(__dirname, "db.json");
fs.readFile(filePath, (err, data) => {
if (err) {
console.error(`Error reading file from disk: ${err}`);
return res.status(500).send(`Error reading file from disk: ${err}`);
}
let jsonData;
try {
jsonData = JSON.parse(data);
} catch (parseErr) {
console.error(`Error parsing JSON file: ${parseErr}`);
return res.status(500).send(`Error parsing JSON file: ${parseErr}`);
}

if (!jsonData[key]) {
console.error(`Key "${key}" not found in the JSON data.`);
return res.status(404).send(`Key "${key}" not found in the JSON data.`);
}

const item = jsonData[key].find((item) => item.id === parseInt(id));

if (!item) {
console.error(`Item with id "${id}" not found in the key "${key}".`);
return res
.status(404)
.send(`Item with id "${id}" not found in the key "${key}".`);
}

res.json(item);
});
});

app.listen(3000, () => {
console.log("Server started on port 3000");
});
7 replies
RRailway
Created by 3arcus on 5/26/2023 in #✋|help
Deploying apps under the same domain
Hello, I have a railway app already configured with a domain, and I want to deploy another app to the same domain, is it possible to have it as a folder of the domain or does it need to be a sub domain? How would I set this up? Thank you
6 replies
RRailway
Created by 3arcus on 5/18/2023 in #✋|help
Trying to deploy Next js 13 app and its failing?
Hey guys, whats the process to deploy a simple Next js app? Version 13. Right now its failing. Is there specific steps? I'm just trying to deploy it from the github repo.
43 replies