Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DATABASE_URL=""
WEB_ORIGIN="http://localhost:5173"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/node_modules
/.env
/generated/prisma
/dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import express from "express";
import cors from "cors";
import { PrismaClient } from "./generated/prisma/client.js";

const app = express();
const client = new PrismaClient();
app.use(express.json());
app.use(cors({ origin: process.env.WEB_ORIGIN }));

app.get("/posts", async (request, response) => {
const posts = await client.post.findMany();
response.json(posts);
});

app.post("/send", async (request, response) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RESTful なら POST /posts なのでそうすべき?

await client.post.create({ data: { message: request.body.message } });
response.send();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sendStatus(201); ?

});

app.listen(3000);
Loading