Answer the question
In order to leave comments, you need to log in
How to correctly set a static folder in koa?
There is a public folder. It's all static.
Usually connected:
app.use(require('koa-static')(__dirname + '/public'));
const router = require('koa-router')();
router.use('/', require('./index').routes());
router.use('/lockers', require('./lockers').routes());
router.use('/decryptors', require('./decryptors').routes());
router.use('/faq',require('./faq').routes());
router.use('/about', require('./about').routes());
router.use('/contacts', require('./contacts').routes());
module.exports = router;
// mount root routes
app.use(router.routes());
const router = require('koa-router')();
const config = require('../config');
const findLocker = require('../helpers/identifier');
const fileUpload = require('../helpers/fileUpload');
router.get('/', function *(next) {
yield this.render('pages/lockers');
});
router.get('/:id', function *(next) {
this.body = 'Single Locker Page: [Locker With Id - ' + this.params.id + ']';
});
router.post('/', function *(next) {
// the body isn't multipart, so busboy can't parse it
if (!this.request.is('multipart/*')) return yield next;
let uploadPath = yield fileUpload(config.uploadDir, this, ['.html', '.txt']);
this.body = yield findLocker(uploadPath);
});
module.exports = router;
<link rel="stylesheet" href="stylesheets/style.css">
Answer the question
In order to leave comments, you need to log in
It is better not to distribute static through node at all, but to use, for example, nginx.
All the same, you will not have a bare node outside.
Everything is correct
For /lockers css will point to localhost/stylesheet/blablabla.css
For /lockers/<something else> to localhost/lockers/stylesheet/blablabla.css
since we went down a level, but we are looking for css relative to the current path .
Use absolute paths relative to the root.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question