send files with requests instead of serving the whole repertory in static
This commit is contained in:
@ -7,8 +7,9 @@ var io = require('socket.io')(http);
|
||||
const cookieParser = require('cookie-parser');
|
||||
app.use(cookieParser());
|
||||
|
||||
// bootstrap
|
||||
app.use('/css', express.static(__dirname + '/node_modules/bootstrap/dist/css'));
|
||||
app.use(express.static('public'));
|
||||
// app.use(express.static('public'));
|
||||
|
||||
const routes = require(__dirname + '/routes');
|
||||
app.use("/", routes);
|
||||
|
@ -1,9 +1,14 @@
|
||||
const path = require('path');
|
||||
|
||||
const mainController = {
|
||||
root: (req, res) => {
|
||||
res.json({
|
||||
message: "Hello, World!",
|
||||
});
|
||||
res.sendFile(path.resolve(__dirname + '/../public/index.html'));
|
||||
},
|
||||
style: (req, res) => {
|
||||
res.sendFile(path.resolve(__dirname + '/../public/style.css'));
|
||||
},
|
||||
script: (req, res) => {
|
||||
res.sendFile(path.resolve(__dirname + '/../public/script.js'));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<link rel="stylesheet" href="/style.css">
|
||||
<script src="/socket.io/socket.io.js" defer></script>
|
||||
<script src="script.js" defer></script>
|
||||
<!--load bootstrap-->
|
||||
|
@ -6,4 +6,12 @@ router
|
||||
.route("/")
|
||||
.get(mainController.root);
|
||||
|
||||
router
|
||||
.route("/style.css")
|
||||
.get(mainController.style);
|
||||
|
||||
router
|
||||
.route("/script.js")
|
||||
.get(mainController.script);
|
||||
|
||||
module.exports = router;
|
||||
|
Reference in New Issue
Block a user