Express js does not serve static files

I set a path like this

var path = require('path');
var express = require('express');
var app = express();
var admin = express();

admin.use(express.static(path.join(__dirname, 'public/')));

// mount admin path
app.use('/admin', admin);

Then I defined some route, for example,

admin.get('/jobs', function(req, res){ 
   res.render('jobs/index');
});

admin.get('/jobs/create', function(req, res){ 
   res.render('jobs/create');
});

In the first route, static files such as js,css,imagesupload without problems. But in the second, it does not upload files.

Files uploaded in a form similar to this

<link rel="stylesheet" href="styles/css/main.css">

NOTE. The styles directory is under a shared folder in my working directory.

So what is the problem? What have I done wrong?

+4
source share
2 answers

admin express, app /admin. , , , /admin. ,

app.use(express.static(path.join(__dirname, 'public')))
+3

: app.use(express.static(path.join(__dirname, 'public')));

href="/styles/css/main.css"?

, .

0

Source: https://habr.com/ru/post/1648772/


All Articles