Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function corsify(req, res) {
// IE 6-7 requires this P3P header
res.setHeader('P3P', 'CP="IDC DSP COR CURa ADMa OUR IND PHY ONL COM STA"')
// Standards-compatible CORS headers
res.setHeader('Access-Control-Allow-Origin', req.get('origin') || '*')
res.setHeader('Access-Control-Allow-Credentials', true)
res.setHeader('Cache-Control', 'no-cache')
}
app.use(require('morgan')('dev'))
app.use(require('body-parser').urlencoded({extended:false}))
app.use(require('body-parser').json())
app.use(require('cookie-parser')())
app.use(require('multer')({ dest: 'temp/ '}).any())
app.get('/nanoajax.min.js', function (req, res) {
fs.createReadStream(__dirname + '/../nanoajax.min.js', {encoding:'utf8'})
.pipe(res)
})
app.get('/get', function (req, res) {
res.send('OK')
})
app.post('/post', function (req, res) {
if (req.body.arg === 'value' && req.body.foo === 'bar')
res.send('OK')
else
res.status(400).send('Bad Request: ' + JSON.stringify(req.body))
})