/* * * 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 dbInit = require("./dbInit"); dbInit.init({ seed : process.env.DB_SEED }); 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.urlencoded({ extended: true })); 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('/get/:id', routes.get); app.get('/log/:id', routes.log); app.get('/health', routes.health); app.get('/search', routes.search); app.get('/*', routes.main); app.post('/*', routes.add); app.patch('/patch/:id', routes.patch); app.put('/*', routes.main); app.delete('/delete/:id', routes.delete); app.listen(port, () => { console.log(`Express.js listening on port: ${port}`); });