https://thuc101.herokuapp.com/
https://thuc101.herokuapp.com/ -->//Cannot GET /
https://thuc101.herokuapp.com/test/ ---->
// url —> /test/ ; protocol —> http ; host —> thuc101.herokuapp.com ; originalUrl —> /test/ ;
https://thuc101.herokuapp.com/test/aaa
url —> /test/aaa ; protocol —> http ; host —> thuc101.herokuapp.com ; originalUrl —> /test/aaa ; param —> aaa ;
Nó không chạy cái https://thuc101.herokuapp.com/
code mình đây
index.js
const express = require('express');
const app = express();
var port=process.env.PORT || 8080
app.use(express.static(__dirname + '/public'));
function obj_to_string(obj) {
var kq = "";
for (var name in obj) {
kq += require('util').format(' %s ---> %s ; ', name, obj[name]);
}
return kq;
}
app.get('/',function(req,res){
//res.send('hello world');
res.render('index');
})
app.get('/test/:cmd', function (req, res) {
var data = {
url: req.url,
protocol: req.protocol,
host: req.get('host'),
originalUrl: req.originalUrl,
param: req.params.cmd,
}
res.send(obj_to_string(data));//( String(data) );//("hello");//( JSON.stringify(data) );
})
app.get('/test', function (req, res) {
var data = {
url: req.url,
protocol: req.protocol,
host: req.get('host'),
originalUrl: req.originalUrl,
}
res.send(obj_to_string(data));//( String(data) );//("hello");//( JSON.stringify(data) );
})
app.listen(port, function () {
console.log('server listen http://localhost:%s', port);
});
index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>hello world</title>
</head>
<body>
<h2>hello world</h2>
</body>
</html>
có bạn nào giải thích giúp
chạy dưới local ok