A
A
Asikov Artur2018-03-11 16:22:20
JavaScript
Asikov Artur, 2018-03-11 16:22:20

Why does the server not see the public subdirectory when making a get request - 404 error?

On server

app.set('port', process.env.PORT || 3000);
app.use(express.static(__dirname + '/public'));
app.use(bodyParser.text({ extended: true })); //было true

app.get('/', function(req, res){
    res.render('home');
});

app.get('/article/:id', function(req, res){
    article_create(req.params.id);
    res.render('home');
});

On the main page - '/' renders perfectly, loads styles, scripts and pictures from the public subdirectory. On the page '/article/3', for example, it does not see the public subdirectory and there is nothing: no styles, no pictures, etc. In the browser I observe "Loading script at address" localhost: 3000/article/js/common.js "failed ." Why is it looking in article if I have set a public subdirectory for this in the middleware
app.use(express.static(__dirname + '/public'));

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question