Spaces:
Sleeping
Sleeping
Create index.js
Browse files
index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const express = require('express');
|
| 2 |
+
const morgan = require('morgan');
|
| 3 |
+
|
| 4 |
+
const app = express();
|
| 5 |
+
|
| 6 |
+
// Gunakan Morgan untuk logging
|
| 7 |
+
app.use(morgan('dev'));
|
| 8 |
+
|
| 9 |
+
// Middleware untuk mengambil URL dengan tanda pagar ()
|
| 10 |
+
app.use((req, res, next) => {
|
| 11 |
+
// Mendapatkan seluruh URL yang dikirimkan oleh klien
|
| 12 |
+
const fullUrl = req.originalUrl;
|
| 13 |
+
|
| 14 |
+
// Memisahkan bagian URL sebelum dan setelah tanda pagar ()
|
| 15 |
+
const urlBeforeHash = fullUrl.split('')[0];
|
| 16 |
+
const hashValue = fullUrl.split('')[1];
|
| 17 |
+
|
| 18 |
+
// Lakukan sesuatu dengan bagian URL yang Anda perlukan
|
| 19 |
+
console.log('URL sebelum hash:', urlBeforeHash);
|
| 20 |
+
console.log('Nilai hash:', hashValue);
|
| 21 |
+
|
| 22 |
+
next();
|
| 23 |
+
});
|
| 24 |
+
|
| 25 |
+
// Routes dan logic lainnya...
|
| 26 |
+
|
| 27 |
+
app.listen(7860, () => {
|
| 28 |
+
console.log('Server berjalan pada port 7860');
|
| 29 |
+
});
|