53 lines
1.2 KiB
TypeScript
53 lines
1.2 KiB
TypeScript
import { PrismaClient } from "@prisma/client";
|
|
import cors from "cors";
|
|
import login from "./api/login";
|
|
import register from "./api/register";
|
|
|
|
const client = new PrismaClient();
|
|
const express = require("express");
|
|
const app = express();
|
|
app.use(express.json());
|
|
app.use(cors());
|
|
|
|
client.$connect();
|
|
app.post("/api/register", register);
|
|
app.post("/api/login", login);
|
|
|
|
app.listen(3000, () => {
|
|
console.log(`Server is running on port 3000`);
|
|
});
|
|
client.$disconnect();
|
|
|
|
/* function verify_token(req, res, next) {
|
|
const token = req.headers["token"];
|
|
if (token) {
|
|
jwt.verify(token, process.env.JWT_SECRET, (err, user) => {
|
|
if (err) {
|
|
res.send("ERROR")
|
|
return
|
|
}
|
|
next();
|
|
})
|
|
return;
|
|
}
|
|
res.status(404);
|
|
res.send("ERROR")
|
|
} */
|
|
|
|
/* app.use('/profile', function (req, res, next) {
|
|
const token = req.headers["authorization"];
|
|
if (token) {
|
|
jwt.verify(token, secret, (err, user) => {
|
|
if (err) {
|
|
res.send("ERROR")
|
|
return
|
|
}
|
|
req.user = user;
|
|
next();
|
|
})
|
|
return;
|
|
}
|
|
res.status(404);
|
|
res.send("ERROR")
|
|
}); */
|