question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Router - what code do I need on the server?

See original GitHub issue

First, 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:closed
  • Created 7 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
cdeutmeyercommented, Feb 22, 2017

@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!

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(path.join(__dirname, 'dist', 'index.html'));
});
 
app.listen(3000)
1reaction
jorgebucarancommented, Feb 22, 2017

@cdeutmeyer But what happens if someone enters the application with a URL containing one of the routes?

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found