mirror of
https://github.com/jiangrui1994/CloudSaver.git
synced 2026-01-11 15:48:47 +08:00
Initial commit for open-source version
This commit is contained in:
30
backend/src/app.ts
Normal file
30
backend/src/app.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import express from "express";
|
||||
import cors from "cors";
|
||||
import cookieParser from "cookie-parser";
|
||||
import routes from "./routes/api";
|
||||
import { errorHandler } from "./middleware/errorHandler";
|
||||
|
||||
const app = express();
|
||||
|
||||
app.use(
|
||||
cors({
|
||||
origin: "*",
|
||||
credentials: true,
|
||||
methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
|
||||
allowedHeaders: ["Content-Type", "Authorization", "Cookie"],
|
||||
})
|
||||
);
|
||||
|
||||
app.use(cookieParser());
|
||||
app.use(express.json());
|
||||
app.use("/", routes);
|
||||
|
||||
// 错误处理
|
||||
app.use(errorHandler);
|
||||
|
||||
const PORT = process.env.PORT || 3000;
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Server is running on port ${PORT}`);
|
||||
});
|
||||
|
||||
export default app;
|
||||
Reference in New Issue
Block a user