forked from digitalocean/sample-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
39 lines (27 loc) · 1007 Bytes
/
index.js
File metadata and controls
39 lines (27 loc) · 1007 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
const express = require('express')
const app = express()
const port = process.env.PORT || 3000
// Middleware để thiết lập các tiêu đề HTTP
app.use((req, res, next) => {
// Thiết lập tiêu đề Cache-Control
res.set('Cache-Control', 'public, max-age=3600'); // Cache trong 1 giờ
// Thiết lập tiêu đề ETag
res.set('ETag', '123456'); // Thay '123456' bằng giá trị ETag thích hợp
// Thiết lập tiêu đề Last-Modified
res.set('Last-Modified', new Date().toUTCString());
next();
});
app.get('/', (req, res) => {
res.send('bearkd fast')
})
app.get('/trk1', (req, res) => {
res.redirect(301, 'https://searchads2024.gotrackier.com/t/Ml8xMg/');
});
app.get('/trk', (req, res) => {
// Lấy URL từ yêu cầu
const reqUrl = req.url;
const index = reqUrl.indexOf('&url=');
const urlParam = reqUrl.substring(index + 5);
res.redirect(301, urlParam);
});
app.listen(port, () => console.log(`Example app listening on port ${port}!`))