Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

res.sendFile instead of res.send & change pi.wifi #4

Open
Pantgom opened this issue Mar 26, 2022 · 1 comment
Open

res.sendFile instead of res.send & change pi.wifi #4

Pantgom opened this issue Mar 26, 2022 · 1 comment

Comments

@Pantgom
Copy link

Pantgom commented Mar 26, 2022

Hi Tom, very good job. I have two questions to improve my project:

  1. How could I change the app.js code to send a file (example index.html, resources.html) instead of send a text (res.send()). I have tried to put sendFile(path/index.html) but nothing happens.
  2. I have tried to change "pi.wifi" in this same file to put something diferent in URL but fails again. If I put "anotherthing.wifi" must I change the name of the service???

Thanks in advance for your project and time.
Pablo

@TomHumphries
Copy link
Owner

Hi Pantgom,

For your first point, you could set a folder to be served. This means any files you request via the URL, or by default index.html, will be returned by the nodejs application.
To serve up files in a folder called public within your nodejs folder you could write:

const path = require('path')
app.use('/', express.static(path.join(__dirname, 'public')))

If you'd like to read more about that, the docs are here.

For your second point, I would have expected you'd only need to change the hostName variable in the nodejs code from pi.wifi to anotherthing.wifi. I'm not sure why that isn't working.

It has been a while since I worked on this guide, and I think the steps can be significantly simplified.
This project appears to achieve a similar goal with less configuration. When I find a bit of free time I'd like to revisit it to see if I can reduce the setup complexity and automate some of it with scripts!

Thanks for the feedback and best of luck with your project!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants