-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
57 lines (41 loc) · 1.44 KB
/
main.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { Application, Router } from "@oak/oak";
import { oakCors } from "@tajpouria/cors";
import routeStaticFilesFrom from "./src/utils/routeStaticFilesFrom.js";
const router = new Router();
const PORT = 8000;
router.post("/api/upload", async (context) => {
const body = await context.request.body.json();
console.log(body.message);
context.response.body = {message: "Hello from backend!"};
});
const app = new Application();
app.use(oakCors());
app.use(router.routes());
app.use(router.allowedMethods());
app.use(routeStaticFilesFrom([
`${Deno.cwd()}/dist`,
]));
console.log(`listening on port: ${PORT}...`);
await app.listen({ port: PORT });
// const express = require("express");
// const cors = require("cors");
// const path = require("path");
// const app = express();
// const port = 8000;
// app.use(cors());
// app.use(express.json());
// app.use(express.static(path.join(__dirname, "dist"))); // Make sure to adjust the path as needed
// app.post("/api/upload", (req, res) => {
// //const { message, content } = req.body;
// console.log(req.body.message);
// // Send a response back to the client
// res.json({ message: "Hello from backend!" });
// });
// // Error handling middleware
// app.use((err, req, res, next) => {
// console.error(err.stack);
// res.status(500).json({ error: "Something went wrong!" });
// });
// app.listen(port, () => {
// console.log(`Server is running on http://localhost:${port}`);
// });