-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
47 lines (42 loc) · 1017 Bytes
/
Copy pathindex.js
File metadata and controls
47 lines (42 loc) · 1017 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
37
38
39
40
41
42
43
44
45
46
47
import express from "express";
import cors from "cors";
import { finalRouter } from "./routes/audio.js";
class Server {
// Use the constructor to create an instance of express and use the class methods.
constructor() {
this.app = express();
this.server();
this.middlewares();
this.routes();
}
// Create a middlewares method.
middlewares() {
this.app.use(express.json());
// CORS added
// CORS added
this.app.use(
cors({
origin: "*",
})
);
}
// Create a method to use the different routes of the app.
routes() {
this.app.get("/", (req, res) => {
res.json({
users: [
{ name: "Nicolás", lastname: "Biondini" },
{ name: "Jonh", lastname: "Doe" },
],
});
});
this.app.use(finalRouter);
}
// Create a method to start the server.
server() {
this.app.listen(3001, () => {
console.log("Dev tutorial API listening on port 3001");
});
}
}
export default new Server();