Skip to content

Instantly share code, notes, and snippets.

@alperbayram
Created February 7, 2022 12:32
Show Gist options
  • Save alperbayram/3214a23d1a406d6838d70970526ccaf8 to your computer and use it in GitHub Desktop.
Save alperbayram/3214a23d1a406d6838d70970526ccaf8 to your computer and use it in GitHub Desktop.
one
const express = require("express");
const path = require("path");
const ContactRoute = require("./Routes/ContactRoute");
const app = express();
//middleware
app.use(express.static(path.resolve(__dirname, "../client/build")));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
//routes
app.use("/", ContactRoute);
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname, "../client/build", "index.html"));
});
//connect port
const port = process.env.PORT || 3001;
app.listen(port, () => {
console.log(`Server listening on ${port}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment