seanpmaxwell / express-generator-typescript

Create a new express app similar to express-generator but with TypeScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Production Mode not working

VittorioAccomazzi opened this issue · comments

right after installing template the production mode is not working :

  1. use npx express-generator-typescript sanitytest to create the template.
  2. compile the application with npm run build
  3. run the application in production mode with npm run start
  4. on a different system connect to the web server on port 8081
    the application will not work correctly, even the css file are not loaded correctly:
    image

i believe here is the issue is that I'm not using https and so the content is blocked. Removing the contentSecurityPolicy from helmet solved he problem:

// Show routes called in console during development
if (process.env.NODE_ENV === 'development') {
    app.use(morgan('dev'));
}

// Security
if (process.env.NODE_ENV === 'production') {
     app.use(helmet({
        contentSecurityPolicy: false,
      }));
}

// Add APIs
app.use('/api', BaseRouter);

I just checked the code, helmet({contentSecurityPolicy: false}) is not in there. All I see is helmet(), you or someone your working with must've added that.

@seanpmaxwell yes, you are correct, I added on my local copy to get the system working. The code just uses helmet(). that is not working with npm run start unless you have https (I believe). In other terms the code is not wrong, it is not setup to work off the box.

Hmm that's really weird cause I'm not having that problem. I just ran a build and accessed localhost:8081 just fine.

@seanpmaxwell I realized that in the instructions above I missed an important step : the client shall be running on a different system than the one of the server. For instance I'm using my raspberry pi as server and my mac as client, and this is what I get when I ran the application inn production mode:
image
I corrected the steps above.

Hmm, can't speak for raspberry pi. I never had that issue on AWS ec2.