Spaces:
Runtime error
Runtime error
atikur-rabbi
commited on
Commit
•
3c1719f
1
Parent(s):
6fd0ead
up
Browse files
app.js
CHANGED
@@ -1,49 +1,49 @@
|
|
1 |
-
const http = require('http');
|
2 |
|
3 |
-
const hostname = process.env.HOST || '0.0.0.0';
|
4 |
-
const port = process.env.PORT || 7860;
|
5 |
|
6 |
-
const server = http.createServer((req, res) => {
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
});
|
11 |
|
12 |
server.listen(port, hostname, () => {
|
13 |
console.log(`Server running at http://${hostname}:${port}/`);
|
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 |
-
|
|
|
1 |
+
// const http = require('http');
|
2 |
|
3 |
+
// const hostname = process.env.HOST || '0.0.0.0';
|
4 |
+
// const port = process.env.PORT || 7860;
|
5 |
|
6 |
+
// const server = http.createServer((req, res) => {
|
7 |
+
// res.statusCode = 200;
|
8 |
+
// res.setHeader('Content-Type', 'text/plain');
|
9 |
+
// res.end('Hello World');
|
10 |
+
// });
|
11 |
|
12 |
server.listen(port, hostname, () => {
|
13 |
console.log(`Server running at http://${hostname}:${port}/`);
|
14 |
});
|
15 |
|
16 |
+
var express = require("express");
|
17 |
+
var app = express();
|
18 |
+
var router = express.Router();
|
19 |
|
20 |
+
var path = __dirname + '/views/';
|
21 |
|
22 |
+
// Constants
|
23 |
+
const PORT = process.env.PORT || 7860;
|
24 |
+
const HOST = '0.0.0.0';
|
25 |
|
26 |
+
router.use(function (req,res,next) {
|
27 |
+
console.log("/" + req.method);
|
28 |
+
next();
|
29 |
+
});
|
30 |
|
31 |
+
// Hello world api
|
32 |
+
router.get("/",function(req,res){
|
33 |
+
res.send("Hello world!");
|
34 |
+
});
|
35 |
|
36 |
+
router.get("/home",function(req,res){
|
37 |
+
res.sendFile(path + "index.html");
|
38 |
+
});
|
39 |
|
40 |
+
router.get("/sharks",function(req,res){
|
41 |
+
res.sendFile(path + "sharks.html");
|
42 |
+
});
|
43 |
|
44 |
+
app.use(express.static(path));
|
45 |
+
app.use("/", router);
|
46 |
|
47 |
+
app.listen(PORT, function () {
|
48 |
+
console.log(`Example app listening on port ${PORT}`)
|
49 |
+
})
|