Redirect 200 to /.netlify/functions/app/ not working


I’ve been struggling with a redirect issue. I’m using a lambda function to serve my express app that I built. For ease of understanding I stripped my app down to a simple json response.


// Dependancies
const express = require('express');
const serverless = require('serverless-http');

const app = express();
const router = express.Router();

router.get('/', (request, response) => {
response.json({"test": "test"});

app.use('/.netlify/functions/app/', router);

module.exports.handler = serverless(app);

What Is Working

  • I can access my app when hitting the functions path directly ‘/.netlify/functions/app/’.

  • When I put in a 301 redirect it successfully redirected to ‘/.netlify/functions/app/’

    from = “/”
    to = “/.netlify/functions/app/”

What Is Not Working

  from = "/"
  to = "/.netlify/functions/app/"
  status = 200

Screen Shot 2020-03-22 at 11.49.12 PM

I even tried changing the from path to: “/hello/” instead of: “/” thinking maybe rewriting “/” wasn’t possible. But I still got the same results. I also played around (:splat) and (force = true) with no success.

Desired Situation
When I hit the index of the site I’d prefer to do a status 200 redirect and hide the ‘/.netlify/functions/app/’ portion of the url

I think that is working, @cpond - our service wouldn’t respond with that message:

Cannot GET /.

Could your function be returning that?

Hey @fool thanks for the reply. It highlighted why I was getting the error. I needed to point to the project root rather then the lambda functions.

Broken Code
app.use(’/.netlify/functions/app/’, router);

Working Code - (With redirect: / /.netlify/functions/app/ 200)
app.use(’/’, router);

1 Like

great, glad its working now!