week5-node-express-knex-pg/app.js

34 lines
678 B
JavaScript
Raw Normal View History

2024-10-21 17:09:40 +01:00
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}!`)
);