is it possible to call the default route from another route in express
See original GitHub issueHi,
In webpack-hot-server-middleware you have your serverRender
function and you set up dev and prod like this:
const express = require('express');
const path = require('path');
const app = express();
if (process.env.NODE_ENV !== 'production') {
const webpack = require('webpack');
const webpackDevMiddleware = require('webpack-dev-middleware');
const webpackHotMiddleware = require('webpack-hot-middleware');
const webpackHotServerMiddleware = require('webpack-hot-server-middleware');
const config = require('./webpack.config.js');
const compiler = webpack(config);
app.use(webpackDevMiddleware(compiler, {
serverSideRender: true
}));
app.use(webpackHotMiddleware(compiler.compilers.find(compiler => compiler.name === 'client')));
app.use(webpackHotServerMiddleware(compiler));
} else {
const CLIENT_ASSETS_DIR = path.join(__dirname, '../build/client');
const CLIENT_STATS_PATH = path.join(CLIENT_ASSETS_DIR, 'stats.json');
const SERVER_RENDERER_PATH = path.join(__dirname, '../build/server.js');
const serverRenderer = require(SERVER_RENDERER_PATH);
const stats = require(CLIENT_STATS_PATH);
app.use(express.static(CLIENT_ASSETS_DIR));
app.use(serverRenderer(stats));
}
Say I have a non root url like some-root
is it possible for me to call the serverRenderer function without redirecting? All I can think to do is this.
express.Router().post('/other-route', (_: Request, res: Response) => {
// do stuff
res.redirect('/');
});
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Setting a Default route in Express.js - GeeksforGeeks
Steps to set the default route in the express app: ... Step 1: Create your project folder. ... Step 4: Require 'express' and...
Read more >javascript - Default route in Express.js - Stack Overflow
I want to setup a default route so that no matter what I type in the URL after localhost:port/ it should all get...
Read more >Routing - Express.js
You can create chainable route handlers for a route path by using app.route() . Because the path is specified at a single location,...
Read more >Express Tutorial Part 4: Routes and controllers - MDN Web Docs
The "about" route (reproduced below) is defined using the Router.get() method, which responds only to HTTP GET requests. The first argument to ...
Read more >How to set up routing in an Express.js project using TypeScript
A route is a system that associates an HTTP request and a function that will execute a process. There can be some parameters...
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 FreeTop 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
Top GitHub Comments
@dagda1 you can mount the middleware on any path you like, e.g.
Alternatively, you could even export a router from the server entry, e.g.
@richardscarrott thank you so much for taking the time to answer my question.