34 lines
807 B
JavaScript
34 lines
807 B
JavaScript
import jsonServer from "json-server";
|
|
import db from "./db/index.js";
|
|
import https from "https";
|
|
import path from "path";
|
|
import fs from "fs";
|
|
import { fileURLToPath } from "url";
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
|
|
const server = jsonServer.create();
|
|
const PORT = 4000;
|
|
|
|
const keyFile = path.join(__dirname, "/certs/localhost-key.pem");
|
|
const certFile = path.join(__dirname, "/certs/localhost.pem");
|
|
|
|
const router = jsonServer.router(db);
|
|
const middleware = jsonServer.defaults();
|
|
|
|
server.use(middleware);
|
|
server.use("/api", router);
|
|
|
|
https
|
|
.createServer(
|
|
{
|
|
key: fs.readFileSync(keyFile),
|
|
cert: fs.readFileSync(certFile),
|
|
},
|
|
server
|
|
)
|
|
.listen(PORT, () => {
|
|
console.log(`Go to https://localhost:${PORT}/`);
|
|
});
|