34 lines
678 B
JavaScript
34 lines
678 B
JavaScript
|
import express from "express";
|
||
|
import SubscriberRouter from "./routes/subscribers.js";
|
||
|
import cors from "cors";
|
||
|
|
||
|
const app = express();
|
||
|
const PORT = process.env.PORT || 5005;
|
||
|
|
||
|
// middleware
|
||
|
app.use(express.json());
|
||
|
app.use(cors());
|
||
|
|
||
|
//routes
|
||
|
app.use("/api/subscriber", SubscriberRouter);
|
||
|
|
||
|
app.use(express.static("public"));
|
||
|
|
||
|
/* landing page GET request */
|
||
|
app.get("/", (req, res) => {
|
||
|
/// send the static file
|
||
|
res.sendFile("index.html", (err) => {
|
||
|
if (err) {
|
||
|
console.log(err);
|
||
|
}
|
||
|
});
|
||
|
});
|
||
|
|
||
|
app.use((req, res) => {
|
||
|
res.status(400).send("Bad Request. Route not found");
|
||
|
});
|
||
|
|
||
|
app.listen(PORT, () =>
|
||
|
console.log(`Express app is listening on port ${PORT}!`)
|
||
|
);
|