1

I am getting these errors when i load my html template in nodejs server the hole template is loaded correctly except icons:

index.html:189 GET http://127.0.0.1:5050/assets/web/assets/mobirise-icons/mobirise-icons.ttf?spat4u net::ERR_ABORTED

index.html:1 GET http://127.0.0.1:5050/assets/web/assets/mobirise-icons/mobirise-icons.woff?spat4u net::ERR_ABORTED

This is my server.js:

var http = require('http');
var fs = require('fs');
var path = require('path');
var url = require('url');
var mysql = require('mysql');

http.createServer(function (request, response) {
    console.log('attente de requètes...');
 var q = url.parse(request.url, true).query;
 var filePath = '.' + request.url;
 console.log(request.url);
 if (filePath == './')
  filePath = './index.html';
 console.log(filePath); 
 var extname = path.extname(filePath);
 var contentType = 'text/html';
 switch (extname) {
  case '.js':
   contentType = 'text/javascript';
   break;
  case '.css':
   contentType = 'text/css';
   break;
 }

 
 fs.exists(filePath, function(exists) {
 

 if (exists) {
   fs.readFile(filePath, function(error, content) {
    if (error) {
     response.writeHead(500);
     response.end();
    }
    else {
     response.writeHead(200, { 'Content-Type': contentType });
     response.end(content, 'utf-8');
    }
   });
  }
  else {
   if(q.email!=null){
    console.log(q.email+" "+q.pswd);
    var con = mysql.createConnection({
      host: "127.0.0.1",
      user: "root",
      password: "",
      database: "Cyberwind"
    });
 
    con.connect(function(err) {
     if (err) throw err;
     con.query("INSERT INTO inscription (email, password, confirmpassword) VALUES ('"+q.email+"','"+q.pswd+"','"+q.confirmpassword+"')", function (err, result, fields) {
      if (err) throw err;
      response.end();
     });
    }); 
   }
   else {
    response.writeHead(404);
    console.log("iciici")
    response.end();
   }
  }
 });
 
}).listen(5050);
console.log('Server running at 5050');

I want to know how to added 2 cases in 'switch (extname)' where the contentType is (.ttf) or (.wof).

Sami
  • 165
  • 4
  • 19
  • I think this anwser will help you: [https://stackoverflow.com/questions/5464362/javascript-using-a-condition-in-switch-case/9055603#9055603](https://stackoverflow.com/questions/5464362/javascript-using-a-condition-in-switch-case/9055603#9055603) – webdynamik Feb 24 '18 at 12:08
  • I just need to added 2 cases in 'switch (extname)' where the contentType is (.ttf) or (.wof) can you tell me how ? – Sami Mar 01 '18 at 16:16
  • var contentType = 'text/html'; switch (extname) { case '.js': contentType = 'text/javascript'; break; case '.css': contentType = 'text/css'; break; case '.woff': contentType = 'application/font-woff'; break; case '.ttf': contentType = 'application/font-sfnt'; break; } ANY HELP !? – Sami Mar 13 '18 at 08:19

0 Answers0