/* * * 2020-05-15T20:28:14.357Z curl -X PUT 'http://localhost:9200/changelog' -d ' { "mappings": { "properties": { "author": { "type": "keyword" }, "content": { "type": "text" }, "created_at": { "type": "date","format": "date_optional_time" } } } }' -H "Content-Type: application/json" * */ /* global process */ "use strict" const authorizationToken = process.env.AUTH_TOKEN || "hello"; const port = process.env.APP_PORT || 3000; const express = require('express'); const app = express(); app.set('view engine', 'pug'); app.use(express.static('public')); const bodyParser = require('body-parser'); app.use(bodyParser.json()); app.use(bodyParser.raw()); app.use(bodyParser.text({ type : "text/*" })); app.disable('x-powered-by'); var cookieParser = require('cookie-parser') app.use(cookieParser('secret')) function requireAuthentication( req, res, next ){ var userAuth = ''; if( req.signedCookies.AuthorizationToken){ userAuth = req.signedCookies.AuthorizationToken; } else if( "AuthorizationToken" in req.query ){ userAuth = req.query.AuthorizationToken; res.cookie('AuthorizationToken', userAuth, {signed: true}); }else if (req.get("AuthorizationToken") ){ userAuth = req.get('AuthorizationToken'); } if( userAuth && userAuth === authorizationToken ){ next(); } else res.end("Auth required");} app.all('*', requireAuthentication); const routes = require( "./routes"); app.get('/log/:id', routes.log); app.get('/health', routes.health); app.get('/search', routes.search); app.post('/*', routes.add); app.get('/*', routes.main); app.patch('/*', routes.main); app.put('/*', routes.main); app.delete('/*', routes.main); app.listen(port, () => { console.log(`Express.js listening on port: ${port}`); });