Tell us what’s happening:
so im not sure what is wrong with my code, since i can actually see the required log on my heroku account
Your code so far
var express = require('express');
var app = express();
var bGround = require('fcc-express-bground');
require('dotenv').config();
app.use( function middleware(req, res, next) {
var something = req.method + " " + req.path + " - " + req.ip;
console.log(something);
next();
})
app.get("/", (req, res) => {
res.sendFile(__dirname + "/views/index.html");
})
app.use(express.static(__dirname + '/public'));
app.use('/public', express.static(__dirname + '/public'));
/*
app.get("/json", (req, res) => {
res.json({"message":"Hello json"})
})*/
app.get("/json", (req, res) => {
var jsonResponse = {"message" : "Hello json"}
if (process.env.MESSAGE_STYLE === "uppercase") {
jsonResponse.message = jsonResponse.message.toUpperCase();
}
res.json()
})
module.exports = app;
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0.
Challenge: Implement a Root-Level Request Logger Middleware
Link to the challenge:
Learn to code. Build projects. Earn certifications.Since 2015, 40,000 graduates have gotten jobs at tech companies including Google, Apple, Amazon, and Microsoft.
Sky020
December 7, 2020, 4:52pm
2
Welcome, duraes.
Would you mind sharing a link to your project code ?
Otherwise, if you are up to it, you can debug what the tests are doing. Here are the tests:
freeCodeCamp/implement-a-root-level-request-logger-middleware.md at master · freeCodeCamp/freeCodeCamp (github.com)
1 Like
Sky020
December 7, 2020, 5:06pm
4
I cannot see anything immediately. Could you provide a link to your project, and I will take a look at that later?
Sky020
December 7, 2020, 5:56pm
6
I see you have changed a lot. But I would recommend going back to what you had from the original post you made, but do not pass a named function. That is, do not call the function middleware.
Hope this helps
so ive tried going back but still it isnt working this is how the code looks now
var express = require('express');
var app = express();
var bGround = require('fcc-express-bground');
require('dotenv').config();
app.use((req, res, next) => {
console.log(req.method + ' ' + req.path + ' - ' + req.ip);
next();
});
app.get("/", (req, res) => {
res.sendFile(__dirname + "/views/index.html");
})
app.use(express.static(__dirname + '/public'));
app.use('/public', express.static(__dirname + '/public'));
/*
app.get("/json", (req, res) => {
res.json({"message":"Hello json"})
})*/
app.get("/json", (req, res) => {
var jsonResponse = {"message" : "Hello json"}
if (process.env.MESSAGE_STYLE === "uppercase") {
jsonResponse.message = jsonResponse.message.toUpperCase();
}
res.json()
})
/*
function getCurrentTime() {
return new Date().toString();
}
app.get("/now", (req, res, next) => {
}, (req, res) => {
res.json({time: req.time});
});
*/
module.exports = app;
Sky020
December 7, 2020, 6:34pm
8
Hey there, I assume you can see the changes I made. I have managed to pass the tests on my side, with your link.
Could you try submit again?
1 Like
im sorry, did you edit the code on repl.it? i tried the way it was there and it wasnt working for me. again, sorry for the inconvenience
https://repl.it/join/emztidti-tiagoduraes
Sky020
December 7, 2020, 8:17pm
10
Yes, I added cors, because I saw this error in the console:
It still works for me. I suggest you do the following:
Click on the RUN button
Open the Live App in a new browser window, and ensure it is working
Submit the link
Hope this works
thank you so much for your help and patience! i should have spotted it immediatly.
your help was precious1