const port = process.env.PORT || 3000;
const express = require("express");
const app = express();
const db = require("./models");
const cors = require("cors");
const bodyParser = require("body-parser");

// Middleware untuk CORS dan body-parser
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));

const spcoImportInfoRoutes = require("./routes/spcoImportInfoRoutes");

app.use("/db", require("./routes/db"));
app.use("/api", spcoImportInfoRoutes); //

app.listen(port, () => {
  console.log(`Server is running on port ${port}`);
});

db.sequelize
  // .sync({ sync: true })
  .authenticate()
  .then(() => {
    console.log("Connection has been established successfully.");
  })
  .catch((error) => {
    console.error("Unable to connect to the database:", error);
  });
