Let us know at any time in the future, if you have any questions about those!
hi dan,
great tutorial. i am picking up a good bit from it so far and am looking forward to moving on to the ‘good’ part with authentication. however, i am a bit stuck when it comes to the css for the site. i’ve just replaced the basic style.css (with the aqua background) with that contained in the gist. when i save and browsersync reloads the content is all loaded below the page, as in, i have to scroll down past a white screen to see what would be the header “WHATABYTE” text. by trial and error i was able to narrow the issue down to this part of the css:
html, body,
#root {
height: 100%;
width: 100%;
}
with that commented out, the page loads almost as expected. as soon as i uncomment and save; back to a white page.
i can narrow it further down to the single line:
height: 100%;
the issue is with the height commented out everything is a little bit s-t-r-e-t-c-h-e-d out. i am not too confident about moving on to images with this artifact in place. also, in your example image it appears the h1, h3, etc text is on the left hand side of the page, while i am seeing it centered across the middle.
i have tried this in both chrome & safari just to be certain it’s not safari (my preferred browser) acting like a jerk in this case.
does this ring any bells? can you suggest anything i can change to get the desired effect? for now i will carry on with the height commented out, but i have a feeling that things are going to be heading downhill from here.
-c.
2 repliesI had a bit of trouble getting browser-sync running. If I run the app with
nodemon ./index.js
Then I’m able to browse to port 8000 and see the basic page through Pug. However, if I use the prescribed
browser-sync start --proxy=localhost:8000 --files='**/*.css, **/*.pug, **/*.js' --ignore=node_modules --reload-delay 10 --no-ui --no-notify
then the browser endlessly spins with ‘Loading…’.
Digging deeper, it looks like I’m successfully connecting to BrowserSync. I can telnet to port 3000, and I can issue a raw HTTP command like GET / HTTP 1.1
, but the session hangs and never responds.
This happened on two different systems with fresh Node and NPM installs. Adding a --logLevel=debug flag didn’t reveal anything obviously amiss.
What might I be doing wrong? How can I go about troubleshooting this?
1 replyI’ll investigate and get back to you! Thanks for reading the post.
I’ll be working on the comments on this thread today. I’ll investigate and get back to you. Thanks for reading the post.
Update:
Howdy, @haiemh! I just re-ran the steps up to adding the custom stylesheet and I didn’t get any errors. The only things that comes to mind is the port maybe being used by something else. Stopping anything running on the ports may help, or a system restart.
I recommend using the link that BrowserSync shows in the console for Local
:
[Browsersync] Proxying: http://localhost:8000
[Browsersync] Access URLs:
-------------------------------
Local: http://localhost:3000
External: http://<Your IP address>:3000
That should work. Are you still having this problem? What version of BrowserSync got installed in your project? The one I installed today is "browser-sync": "^2.26.7",
and it’s working fine.
Howdy, @craigz! I re-ran the steps up to when the custom stylesheet is added and everything is working as expected I am not sure what could be happening on your end. Another teammate also tested this prior to the post going live and we reported no issues.
Are you still having the problem? Would you like to share a repo with the code you got so far? What operating system are you using?
Best regards!
1 replyhi @dan-auth0, thanks for getting back to me. i’ve created a repo on GitHub for the project located at: github link.
when you load the page at localhost:3000 the screen is all white, however if you scroll down, you’ll see the image followed by the text and finally the button. i just completely replaced my version of public/style.css with the text of the gist and updated to the point of adding the graphic so there should be none of my ‘troubleshooting’ evident to be the reason things aren’t working. (i had never got it working anyhow, however i was able to greatly reduce the whitespace at the top of the page; but then the graphic was a 4 pixel tall strip. not much better!)
i am working on a mac (mojave) and have tried this in the chrome browser as well as safari with similar results.
i’m curious to hear how it works for you after you’ve had a chance to check it out. thanks again.
-c.
1 reply@craigz Thank you for sharing the repo! It helps tremendously. I found the source of trouble for your project:
That’s the tricky part of Pug, white spacing controls structuring:
div.View.WelcomeView
h1.Banner WHATABYTE
The Banner
element gets pushed down because it’s a sibling of the WelcomeView
element. If you indent it, it becomes its child
At that point in the tutorial, the index.pug
template should look like this:
extends layout
block layout-content
div.View.WelcomeView
h1.Banner WHATABYTE
div.Message
div.Title
h3 Making the Best
h1 Food For Devs
span.Details Access the WHATABYTE Team Portal
div.NavButtons
if isAuthenticated
a(href="/user")
div.NavButton Just dive in!
else
a(href="/login")
div.NavButton Log in
Please let me know if that fixes the issue
hi @dan-auth0,
so much closer now. the parent-child relationship now appears to work correctly and the image loads in the way i would expect. the only remaining issue is that the entire page remains pushed down an entire page of whitespace. so the initial page load is all white and unless you know to scroll down a page, it appears there is nothing there. i had entirely focused on the css as that is entirely unknown to me, i’d not even thought about what pug was doing there. i’ll focus on that a bit more and see how it goes. i’ll update here if i manage to work things out, otherwise if you have any other ideas as to why the whitespace, let me know. i’ve updated the repo with the changes to index.pug.
thanks again for taking a look at this.
-c.
1 replyCool, glad it worked
Let us know @craigz if you have any more questions!
Hi dan, how are you doing?
I’m using express 4.17.1. I followed the post but got a problem on app.use(express.static(...))
. Basically it didn’t middlewared anything at all. I went to documentation and saw that it used relative path instead of path.join(base, public). I removed the path.join thing and it worked fine.
The question is, you said to use path.join to have a env independent file reference, but didn’t work for me. Do you think it might be the express version I have? does using app.use(express.static("public"));
makes it env-dependent? how come?
Thanks,
Ale
Hello, Alejandro! Thank you for reading the blog post and also for joining our Auth0 Community. Today, I’ve been working on some Express content and I’ve been auditing this blog post. Let me run this again and see if I can spot any problems
Alejandro, I just tested this blog post from start to end and I saw no error and all the assets were served correctly. This is what my package.json
looks like:
{
"name": "whatabyte-portal",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "nodemon ./index.js",
"ui": "browser-sync start --proxy=localhost:8000 --files='**/*.css, **/*.pug, **/*.js' --ignore=node_modules --reload-delay 10 --no-ui --no-notify"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"browser-sync": "^2.26.7",
"nodemon": "^1.19.4"
},
"dependencies": {
"express": "^4.17.1",
"pug": "^2.0.4"
}
}
The statement to serve assets from the public
directory is:
app.use(express.static(path.join(__dirname, "public")));
__dirname
corresponds to the root project directory as it is the parent folder of the index.js
file where that statement is being executed. For that file reference to work, the public
directory must be a sibling of the index.js
file as well. If you place public
in another area or within a directory that is child to the root project directory, the reference won’t work.
The use of path.join
is to create file paths that work across operating systems. So if that statement is run on Windows, you’ll get the right pathname delimiters for Windows – the same goes for macOS, Linux, etc. Some operating systems use /
while others use \
to delimit file paths.
I’d recommend taking a look at your project structure to ensure that the references work. Please let me know if you have further questions Happy to help!
Good afternoon, error at this stage. I am using Visual Studio Code.
/ *
Hello, Manyhp. Welcome to the Auth0 Community. That first app.get ("/", (req, res) => { … });
is a placeholder for the existing code to help you visually identify where you need to add the new function:
app.get ("/ user", (req, res) => {
res.render (“user”, {title: “Profile”, userProfile: {nickname: “Auth0”}});
});
You don’t need to add or replace app.get ("/", (req, res) => { … });
in your code, only add the new function below it.
thank you very much for your reply
but still routing doesn’t work
block code