const express = require("express");
const fs = require("fs");
const https = require("https");
const os = require("os");
const path = require("path");
const setupProxy = require("./src/setupProxy");
const serveStatic = require("serve-static");
var history = require("connect-history-api-fallback");

const PORT = 5001;
const app = express();
setupProxy(app);

app.use(history());
// app.use(express.static("build"));
app.use(serveStatic("build", { index: ["index.html", "index.htm"] }));

https
  .createServer(
    {
      key: fs.readFileSync(path.join(os.homedir(), ".cert/key.pem")),
      cert: fs.readFileSync(path.join(os.homedir(), ".cert/cert.pem")),
    },
    app
  )
  .listen(PORT, () => {
    console.log("预览服务已开启");
    console.log(`https://localhost:${PORT}`);
  });
