server.js 1.25 KB
const express = require("express");
const bodyParser = require("body-parser");
const fs = require("fs");
const cors = require("cors");
const { getPeed, getSubjects, login } = require("./libs/E_Campus.js");

const loginRouter = require("./routers/Login");
const dbRouter = require("./routers/DB");

const app = express();

app.use(
  cors({
    origin: "http://localhost:3000",
    credentials: true,
  })
);
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

app.post("/", (req, res) => {
  res.send({ body: req.body });
  console.log("listened /");
});

app.use("/login", loginRouter);
app.use("/db", dbRouter);

// fs.readFile("server/libs/login.pvdata", "utf8", async (err, data) => {
//   if (err) {
//     console.error(err);
//     console.log("server/libs/login.pvdata에 ID\\nPW를 작성");
//     return;
//   }
//   const page = await login(...data.split("\r\n"));
//   if (page) {
//     const feed = await getPeed(page);
//     const subjects = await getSubjects(page);
//     console.log({ feed, subjects });

//     app.listen(3001, function () {
//       console.log("listening on 3001");
//     });
//   } else console.log("Incorrect user ID or password.");
// });

app.listen(3001, function () {
  console.log("listening on 3001");
});