I'm trying to set the twilio client quickstart app up in nodejs. I'm using nginx as a reverse proxy so that requests made to http://example.com/calls
, nginx routes that to localhost:3000, where I have the twilio nodejs quickstart running. The problem is that expressjs is expecting to serve files as if I were calling http://example.com
with no subdirectory.
I understand that I would be able to use app.get, but I'm not sure how in the way this particular app is configured. Right now it has:
const http = require('http');
const path = require('path');
const express = require('express');
const bodyParser = require('body-parser');
const router = require('./src/router');
// Create Express webapp
const app = express();
app.use(express.static(path.join(__dirname, 'public')));// <-Pretty sure I'm supposed to change something here
app.use(bodyParser.urlencoded({extended: false}));
In the index.js that node is running on is at
/var/www/example.com/calls/index.js
The static content that I thought ought to be served is at
/var/www/example.com/calls/public/index.html
How to I change this to make express find the content?
Nodejs is definitely recieving the request. The error is Cannot GET /calls/
and the header X-Powered-By
is present and set to Express
EDIT:
I would have liked to follow the instructions here but my at&t firewall isn't letting me make changes. Since I have ports 80 and 443 open already I decided my next best bet was to proxy the application to a subfolder of a domain I already have running on my system. Both of the solutions offered so far allow the index.html file inside of the /public
folder to be served, but nginx is failing to serve the js file or the the css files located in the same folder.
app.use('/calls',express.static(path.join(__dirname, '/public')));
is currently serving the index.html file at https://example.com/calls, which is great. What stinks is the nginx somehow isn't passing the requests for https://example.com/calls/site.css along to nodejs.
If I add the line
rewrite ^/cawls(.*)$ $1 break;
then nothing gets found.
Here's the nginx call.
location ~/calls(.*)$ {
# rewrite ^/calls(.*)$ $1 break;
proxy_pass http://127.0.0.1:3000;
}
Here and here are previous questions related to this problem that no one seems to have an answer for.