Spaces:
Paused
Paused
Create index.js
Browse files
index.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const express = require('express');
|
| 2 |
+
const app = express();
|
| 3 |
+
const path = require('path');
|
| 4 |
+
const bodyParser = require("body-parser");
|
| 5 |
+
const PORT = process.env.PORT || 7860;
|
| 6 |
+
|
| 7 |
+
// Events limit à¶‘à¶š à·€à·à¶©à·’ කිරීම
|
| 8 |
+
require('events').EventEmitter.defaultMaxListeners = 500;
|
| 9 |
+
|
| 10 |
+
// Middleware (මේව෠routes වලට කලින් à¶à·’යෙන්න ඕනේ)
|
| 11 |
+
app.use(bodyParser.json());
|
| 12 |
+
app.use(bodyParser.urlencoded({ extended: true }));
|
| 13 |
+
|
| 14 |
+
// CSS, JS, Images වගේ static files load වෙන්න මේක ඕනේ
|
| 15 |
+
app.use(express.static(path.join(__dirname, '.')));
|
| 16 |
+
|
| 17 |
+
// Routes
|
| 18 |
+
let code = require('./pair');
|
| 19 |
+
app.use('/code', code);
|
| 20 |
+
|
| 21 |
+
// Pairing page එක පෙන්වන්න
|
| 22 |
+
app.get('/pair', (req, res) => {
|
| 23 |
+
res.sendFile(path.join(__dirname, 'pair.html'));
|
| 24 |
+
});
|
| 25 |
+
|
| 26 |
+
// Main UI à¶‘à¶š පෙන්වන්න (Link à¶‘à¶šà¶§ ගිය ගමන් පෙනෙන à¶à·à¶±)
|
| 27 |
+
app.get('/main', (req, res) => {
|
| 28 |
+
res.sendFile(path.join(__dirname, 'main.html'));
|
| 29 |
+
});
|
| 30 |
+
|
| 31 |
+
// Root URL à¶‘à¶šà¶§ (/) ගිය ගමන් පෙන්වන දේ - මෙà¶à¶±à¶§ main.html එකම දෙමු
|
| 32 |
+
app.get('/', (req, res) => {
|
| 33 |
+
res.sendFile(path.join(__dirname, 'main.html'));
|
| 34 |
+
});
|
| 35 |
+
|
| 36 |
+
// Server එක Start කිරීම
|
| 37 |
+
app.listen(PORT, () => {
|
| 38 |
+
console.log(`
|
| 39 |
+
---------------------------------------
|
| 40 |
+
Server is live on port: ${PORT}
|
| 41 |
+
Hugging Face URL: http://localhost:${PORT}
|
| 42 |
+
---------------------------------------
|
| 43 |
+
`);
|
| 44 |
+
});
|
| 45 |
+
|
| 46 |
+
module.exports = app;
|