|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
747 bytes
|
| Line | |
|---|
| 1 | /**
|
|---|
| 2 | * Copyright (c) 2015-present, Facebook, Inc.
|
|---|
| 3 | *
|
|---|
| 4 | * This source code is licensed under the MIT license found in the
|
|---|
| 5 | * LICENSE file in the root directory of this source tree.
|
|---|
| 6 | */
|
|---|
| 7 | 'use strict';
|
|---|
| 8 |
|
|---|
| 9 | const path = require('path');
|
|---|
| 10 |
|
|---|
| 11 | module.exports = function createRedirectServedPathMiddleware(servedPath) {
|
|---|
| 12 | // remove end slash so user can land on `/test` instead of `/test/`
|
|---|
| 13 | servedPath = servedPath.slice(0, -1);
|
|---|
| 14 | return function redirectServedPathMiddleware(req, res, next) {
|
|---|
| 15 | if (
|
|---|
| 16 | servedPath === '' ||
|
|---|
| 17 | req.url === servedPath ||
|
|---|
| 18 | req.url.startsWith(servedPath)
|
|---|
| 19 | ) {
|
|---|
| 20 | next();
|
|---|
| 21 | } else {
|
|---|
| 22 | const newPath = path.posix.join(servedPath, req.path !== '/' ? req.path : '');
|
|---|
| 23 | res.redirect(newPath);
|
|---|
| 24 | }
|
|---|
| 25 | };
|
|---|
| 26 | };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.