Getting started:
Related tutorials:
| res.setHeader('Access-Control-Allow-Origin', '*'); | |
| res.setHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content, Accept, Content-Type, Authorization'); | |
| res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS'); |
| const normalizePort = val => { | |
| const port = parseInt(val, 10); | |
| if (isNaN(port)) { | |
| return val; | |
| } | |
| if (port >= 0) { | |
| return port; | |
| } | |
| return false; |
Getting started:
Related tutorials:
| module.exports = fn => { | |
| return (req, res, next) => { | |
| Promise.resolve(fn(req, res)).catch(next); | |
| } | |
| }; | |
| // EXAMPLE OF USAGE: | |
| //const catchException = require('./utils/catchException') | |
| //app.get('/', catchExceptions(async (req, res) => { | |
| // ... |
| app.disable("x-powered-by"); |
| ### Example #1 ### | |
| $ docker ps -a | |
| CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES | |
| 2e23d01384ac iperf-v1:latest "/usr/bin/iperf -s" 10 minutes ago Up 10 minutes 5001/tcp, 0.0.0.0:32768->5201/tcp compassionate_goodall | |
| # Append the container ID (CID) to the end of an inspect | |
| $ docker inspect --format '{{ .NetworkSettings.IPAddress }}' 2e23d01384ac | |
| 172.17.0.1 | |
| ### Example #2 ### | |
| # Add -q to automatically parse and return the last CID created. |
| Kill-port: | |
| //To list any process listening to the port 8080: | |
| sudo lsof -i:8080 | |
| //To kill any process listening to the port 8080: | |
| sudo kill $(lsof -t -i:8080) | |
| //or more violently: | |
| sudo kill -9 $(lsof -t -i:8080) | |
| //(-9 corresponds to the SIGKILL - terminate immediately/hard kill) | |
| On freeze: |
| module.exports = ms => { | |
| return new Promise((resolve, reject) => { | |
| setTimeout(resolve, ms); | |
| }) | |
| } | |
| //EXAMPLE OF USAGE: | |
| //const promuseTimeout = request('./utils/promiseTimeout'); | |
| //(async () => { | |
| // await promiseTimeout(1000); |