1.0.7 • Published 5 years ago
@oauthanon/serve v1.0.7
OAuthAnon: Serve
Collection of utilities for serving HTTP(S) content.
Function: sigintServer
Add a SIGINT handler which gracefully closes a server.
import { sigintServer } from '@oauthanon/utils';
const app = express();
const server = app.listen();
sigintServer(server);Function: spa
Simple SPA server based on Express.
- Prints out server static directory and port.
- Prints out morgan
combinedlogging. - Serves
index.htmlin instead of returning 404s. - Uses
PORTenvironment variable if no port is given. - Gracefully shutdown on
SIGINT.
import { spa } from '@oauthanon/utils';
spa(
// Optional root directory - Defaults to process.cwd()
`${__dirname}/static`,
// Optional port - Defaults to process.env.PORT or 8080
8080,
// Optional hostname - Defaults to "0.0.0.0"
'0.0.0.0',
);CLI: spa [root]
Simple CLI wrapper for the spa function. Accepts one optional argument for the content root path.
yarn run spa ./build