-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
39 lines (32 loc) · 906 Bytes
/
app.js
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
37
38
39
const express = require("express");
const cors = require("cors");
const path = require("path");
const conversionRoutes = require("./routes/conversionRoutes");
const app = express();
const port = 3000;
// Middleware
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cors());
app.use(express.static("public"));
// Routes
app.use("/api/convert", conversionRoutes);
// Serve frontend
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname, "public", "index.html"));
});
app.get("/test", (req, res) => {
res.send("Hello, World!");
});
// Error handling middleware
app.use((err, req, res, next) => {
console.error("Server error:", err.stack);
res.status(500).json({
error: "Something went wrong!",
message: err.message,
});
});
// Start server
app.listen(port, () => {
console.log(`FormatFusion service running at http://localhost:${port}`);
});