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:
I removed my static route, I have a route folder though can it be problematic?
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?
