i used node.js , angular.js build simple web application based on express framework, when try upload .css
file, got following error message :
“the stylesheet not loaded because mime type, ”text/html“ not ”text/css"
server.js
var express = require('express'); var app = express(); var bodyparser = require('body-parser'); var pg = require('pg'); var jwt = require('jsonwebtoken'); // create, sign , verify tokens var morgan = require('morgan'); // application front end app.get('*',function(req,res){ res.sendfile('./public/index.html') }) app.listen(port); console.log('loganalysiswebapp happens on port '+port);
index.html
<!doctype html> <html lang="fr"> <head> <meta charset="utf-8"> <title>log analysis web app</title> <link rel="stylesheet" type="text/css" href="/public/stylesheets/style.css"> </head> <body> <h1>text example</h1> </body> </html>
my project has following structure :
to serve static files such images, css files, , javascript files, use express.static built-in middleware function in express.
app.use(express.static('public'));
now, can load files in public directory:
http://www.domain.com/stylesheets/style.css
here official documentation page on serving static resources.
Comments
Post a Comment