Reputation: 15303
In my express
app, I have declared the static folder. And I am keeping my index.html
as well in the static folder. But I have created a new router
for a new purpose. when i create a new router
my static folder always trying to get the assets using the new router
declared. any one help me to sort this issue?
here is my code and issue :
var
express = require("express"),
app = express(),
Router = express.Router;
app.use( express.static(__dirname + '/puplic')); //my public folder
var oneTime = new Router(); //my new router
oneTime.get("*", function( req, res ) {
res.sendFile( __dirname + "/public/oneTime/index.html");
});
app.use("/oneTime", oneTime);
app.listen( 9000, function portCallback() {
console.log(" I am started!!" , __dirname);
})
But my app trying to get the angular
js like this:
what is the issue?
here is the html how i call my angualr:
<script src="oneTime/angular.min.js"></script>
actually I am expecting like this:
Upvotes: 0
Views: 88
Reputation: 2249
Option 1
You can change this line:
app.use( express.static(__dirname + '/puplic')); //my public folder.
to
app.use('/oneTime', express.static(__dirname + '/puplic')); //my public folder
Option 2
I am assuming you have a js
folder in the public folder, then you need to change your html code:
<script src="js/angular.min.js"></script>
and the server code will be
app.use( express.static(__dirname + '/puplic')); //my public folder.
Upvotes: 1
Reputation: 3361
var express = require("express"),
var app = express();
app.use(express.static(__dirname + 'puplic')); //my public folder
app.get("*", function( req, res ) {
res.sendFile( __dirname + "/public/index.html");
});
app.listen( 9000, function portCallback() {
console.log("Server is Running on 9000");
});
Upvotes: 0