Skip to content

Instantly share code, notes, and snippets.

@LazyFatArrow
Last active August 19, 2019 12:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LazyFatArrow/0771f30bf8d03d58392829b79722164b to your computer and use it in GitHub Desktop.
Save LazyFatArrow/0771f30bf8d03d58392829b79722164b to your computer and use it in GitHub Desktop.
import { Injectable, NestMiddleware } from '@nestjs/common';
import { Request, Response } from 'express';
import { join } from 'path';
@Injectable()
export class ServeHTMLMiddleware implements NestMiddleware {
use(req: Request, res: Response, next: () => void) {
// here you can check if the requested path is your api endpoint, if that's the case then we have to return next()
if (req.path.includes('graphql')) {
return next();
}
// change the path to the correct html page path in your project
res.sendFile(join(process.cwd(), '../client/dist/index.html'));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment