-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (30 loc) · 1.41 KB
/
index.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
// http://localhost:8080/users/91283712?sort=price
import express from 'express';
const app = express();
const port = process.env.PORT || 8080;
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "http://127.0.0.1:5173"); // Update to match the domain you will make the request from
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
app.get('/', (req, res) => res.send(`
<h1>hello welcome to my website</h1>
<a href="/news">go to news page</a>`));
import dataCont from './continent.json' assert { type: 'json' };
app.get('/dataContinent', (req, res) => res.send(
dataCont
));
app.get('/news', (req, res) => res.send('this is the news page welcome!'));
app.get('/data', (req, res) => res.json({name:"bruno", bio:"i like coding"}));
app.get('/users/:id', (req, res) => {
console.log(req.params.id); // 1
console.log(req.query); // name
res.send("sorry database is offline, try again later")
});
app.listen(port, () => console.log(`Server listening at http://localhost:${port}`));
// import express from 'express';
// const app = express();
// const port = process.env.PORT || 8080;
// app.get('/', (req, res) => res.send('Hello World!'));
// app.get('/news', (req, res) => res.send('this is the news page welcome!'));
// app.listen(port, () => console.log(`Server listening at http://localhost:${port}`));