Not serving my public folder.
See original GitHub issueI have tried following codes but i am unable to see static files.
'use strict'
const path = require('path');
const router = require('./routes')
const Koa = require('koa')
const views = require('koa-views')
const passport = require('koa-passport')
const serve = require('koa-static')
const app = new Koa()
// Serving public assets.
app.use(serve('public'))
app.listen(8080);
My folder structure is that on root i have public folder.
public/
├── css
└── app.css
web
├── index.js // This contains above code. the code is complete.
index.js // Start script. node index.js
I have tried to provide all these paths in serve arguments
app.use(serve(__dirname+ '/../public')) // resolves to valid path
app.use(serve('/<complete-absolute-path>/public')) // resolves to valid path.
app.use(serve(__dirname+ '/public')) // for testing only, path is incorrect.
app.use(serve('./public')) // for testing only, path is incorrect.
Also when i added logs to check if path is resolved correctly then first two paths from above commands are valid.
but when i visit
http://localhost:8080/public/css/app.css
It won’t serve static file.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:10 (1 by maintainers)
Top Results From Across the Web
node.js - express.static not serving .html file from public folder
To serve your documents, just rename document.html to index.html and bind the directory: app.use('/document', express.static('document'));.
Read more >Create and share a public folder in Outlook - Microsoft Support
Public folders in Outlook give you a great place to collect, organize, and share information about particular topics or projects within an organization....
Read more >I'm having trouble with a shared folder - Dropbox Help
There are a few situations when your shared folders might not work as expected. Learn how to fix problems with shared folders.
Read more >Serving static files in Express
For example, use the following code to serve images, CSS files, and JavaScript files in a directory named public : app.use(express.static('public')).
Read more >Serving Static Resources in Node.js - TutorialsTeacher
The following example serves static resources from the public folder under the ... This will not break your application even if you run...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think the issue here is that when you do
app.use(serve('.'))
, you’re serving your whole directory, so if your files are in/public
, you make a request tohttp://.../public/files
to get them. When you useapp.use(serve('./public'))
, that same file is now served at the web root:http://.../files
. Another issue suggests using koa-mount to resolve this, so that’s what I did:Try that and see if it works for you?
app.use(mount("/public", serve("./public")));
does nothing for me.