ZijianHe / koa-router

Router middleware for koa.
MIT License
4.85k stars 408 forks source link

HELP! Wrong static file path with koa-static #488

Open czweb2017 opened 5 years ago

czweb2017 commented 5 years ago

Document struct: static/img/1.jpg src/view src/routes/index.js

Static file: app.use(staticServe('static/'));

Router path: router.get('/aaa/bbb', () => { blabla... ctx.render(.......) })

But, I get a wrong path result on front end: 'http://localhost:8888/aaa/1.jpg' 404

HELP!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

duylddev commented 5 years ago

You should let nginx or apache serve static file instead of nodejs. Link: https://hashnode.com/post/why-is-it-not-recommended-to-serve-static-files-from-nodejs-ciibz8flv01duj3xt4lxuomp3

czweb2017 commented 5 years ago

Well, it was resolved. Please use '/css/index.css' on IMG or LINK elements. Don't lose '/' as begain.