Hosting my front-end using github pages and back-end using render

Hello, I was able to host my front-end on github pages. Now, when it comes to render, I link render to my back-end repo. The server successfully deploy it and give me a particular url. But when I use postman to test the link it doesn't work, here is my code:
import express from "express";
import { readFileSync } from "fs";
import { getProperties } from "properties-file";
import path from "path";
import { cwd } from "process";
import cors from "cors";
import morgan from "morgan";
import { MongoClient } from "mongodb";
import { productRouter } from "./routes/products.js";
import { orderRouter } from "./routes/orders.js";

const configurationPath = path.join(
`${cwd()}`,
"configurations",
"configurations.properties"
);

const allowedOrigins = [
"http://localhost:8080",
"https://users.github.io/Lesson-page/",
];
const corsOptions = { origin: allowedOrigins };
const uri = getProperties(readFileSync(configurationPath)).uri;

// Create a MongoClient
const client = new MongoClient(uri);
let db;

const app = express();
app.use(
morgan(":method :url :status :res[content-length] - :response-time ms")
);

const port = getProperties(readFileSync(configurationPath)).port;

app.use(cors(corsOptions));

// middleware to parse body of Content-type: application/json
app.use(express.json());

// Product route
app.use("./api/products", productRouter);

// Order route
app.use("./api/orders", orderRouter);

async function run() {
try {
await client.connect();

// Send a ping to confirm a successful connection
await client.db("admin").command({ ping: 1 });
console.log(
"Pinged your deployment. You successfully connected to MongoDB!"
);
db = client.db("Lesson");

app.listen(port, () => {
console.log(`app listening on port ${port}`);
});
} catch (err) {
console.log(err);
}
}
run().catch(console.dir);
export { db };
import express from "express";
import { readFileSync } from "fs";
import { getProperties } from "properties-file";
import path from "path";
import { cwd } from "process";
import cors from "cors";
import morgan from "morgan";
import { MongoClient } from "mongodb";
import { productRouter } from "./routes/products.js";
import { orderRouter } from "./routes/orders.js";

const configurationPath = path.join(
`${cwd()}`,
"configurations",
"configurations.properties"
);

const allowedOrigins = [
"http://localhost:8080",
"https://users.github.io/Lesson-page/",
];
const corsOptions = { origin: allowedOrigins };
const uri = getProperties(readFileSync(configurationPath)).uri;

// Create a MongoClient
const client = new MongoClient(uri);
let db;

const app = express();
app.use(
morgan(":method :url :status :res[content-length] - :response-time ms")
);

const port = getProperties(readFileSync(configurationPath)).port;

app.use(cors(corsOptions));

// middleware to parse body of Content-type: application/json
app.use(express.json());

// Product route
app.use("./api/products", productRouter);

// Order route
app.use("./api/orders", orderRouter);

async function run() {
try {
await client.connect();

// Send a ping to confirm a successful connection
await client.db("admin").command({ ping: 1 });
console.log(
"Pinged your deployment. You successfully connected to MongoDB!"
);
db = client.db("Lesson");

app.listen(port, () => {
console.log(`app listening on port ${port}`);
});
} catch (err) {
console.log(err);
}
}
run().catch(console.dir);
export { db };
I removed my static route, I have a route folder though can it be problematic?
4 Replies
Faker
FakerOP3d ago
Pinged your deployment. You successfully connected to MongoDB!
app listening on port 8080
Pinged your deployment. You successfully connected to MongoDB!
app listening on port 8080
These are the 2 console log statements I got does port matters here? hmm manage to make it work, question though, render always send a GET 404 request,:
GET / 404 139 - 1.306 ms
GET /api/products 200 1528 - 332.486 ms
GET /api/products 304 - - 329.575 ms
GET / 404 139 - 1.306 ms
GET /api/products 200 1528 - 332.486 ms
GET /api/products 304 - - 329.575 ms
anyone knows why? is it expecting an app.get with / as path?
Jochem
Jochem3d ago
that looks like the log from a webserver. Something is performing a GET request to / and it's sending a 404 status code as a response
13eck
13eck3d ago
You have nothing mapped to / so it's 404'ing
Faker
FakerOP2d ago
yeah, it's strange though I don't really send a request to / on my front-end I should verify thanks !

Did you find this page helpful?