-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
36 lines (28 loc) · 805 Bytes
/
server.js
File metadata and controls
36 lines (28 loc) · 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import express from "express";
import cors from "cors";
import publicRoutes from "./routes/public.js";
import privateRoutes from "./routes/private.js";
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient({
log: ["query", "info", "warn", "error"],
});
const app = express();
app.use(express.json());
app.use(cors());
app.post("/usuarios", async (req, res) => {
await Prisma.user.create({
data: {
email: req.body.email,
name: req.body.name,
age: req.body.age,
},
});
res.status(201).json(req, body);
});
app.get("/usuarios", async (req, res) => {
const users = await prisma.user.findMany();
res.status(200).json(users);
});
app.use("/", publicRoutes);
app.use("/", privateRoutes);
app.listen(27017, () => console.log("Servidor ok"));