Router - what code do I need on the server?
See original GitHub issueFirst, I want to say thank you!!! I’m really loving HyperApp!
I’ve implemented the default router client side and it works great. But what happens if someone enters the application with a URL containing one of the routes?
My express server gets confused because I’m only serving the index.html at the root of the application. How do I connect it to the HyperApp routing?
Here is my server code.
`var express = require(‘express’) var path = require(‘path’); var app = express()
app.use(express.static(path.join(__dirname, ‘/dist’)));
app.get(‘/’, function (req, res) { res.sendFile(‘index.html’); });
app.listen(3000)`
Thanks!
Issue Analytics
- State:
- Created 7 years ago
- Comments:12 (7 by maintainers)
Top Results From Across the Web
How to Setup and Configure your Home Router
The first step is to setup Wi-Fi access on your Laptop/PC using the Wi-Fi details (SSID and password). Now you should be able...
Read more >How to choose router's connection type for your network?
Normally, a router has 3 connection types, PPPoE, DHCP and Static IP. What's the difference between them? How should you choose the correct...
Read more >How to Connect to Your Home Router as an Administrator
Identify the IP address of the router. Most routers are manufactured to use a default address such as 192.168.0.1, 192.168.1.1, 192.168.2.1, or ...
Read more >How to Set Up a Router - Step-by-Step
Learn how to set up a router and take the stress out of configuring your router including determining best location, testing connections and...
Read more >Understanding DHCP Server Router Configuration
This article will show how we can configure a router to act as a DHCP server.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@dodekeract & @jbucaran I ended up adjusting the server code based on your suggestions and it works great. I’m going to need some routes for a data access API later so I wont be able to use /* once that’s in place but I’m pretty sure I’ll just need to serve index.html on any of the routes that are handled client side. Below is the adjusted server code in case it helps anyone else… Thanks again for your help!
Hi! 👋 I’m glad you’re having fun with HyperApp!
If your client application handles all your routes, you could make your server to redirect all /* routes to
index.html
, then HyperApp’s router will do what it’s supposed to do.Does that make sense?