2020-05-15 23:24:56 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
2020-05-15T20:28:14.357Z
|
2020-05-17 23:13:20 +00:00
|
|
|
curl -X PUT 'http://localhost:9200/changelog' -d '
|
2020-05-15 23:24:56 +00:00
|
|
|
{
|
|
|
|
"mappings": {
|
|
|
|
"properties": {
|
|
|
|
"author": { "type": "keyword" },
|
|
|
|
"content": { "type": "text" },
|
2020-05-17 23:13:20 +00:00
|
|
|
"created_at": { "type": "date","format": "date_optional_time" }
|
2020-05-15 23:24:56 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-17 23:13:20 +00:00
|
|
|
}' -H "Content-Type: application/json"
|
|
|
|
|
2020-05-15 23:24:56 +00:00
|
|
|
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* global process */
|
|
|
|
|
|
|
|
"use strict"
|
|
|
|
|
2020-05-16 16:20:04 +00:00
|
|
|
const authorizationToken = process.env.AUTH_TOKEN || "hello";
|
|
|
|
const port = process.env.APP_PORT || 3000;
|
|
|
|
|
2020-05-15 23:24:56 +00:00
|
|
|
|
|
|
|
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');
|
|
|
|
|
|
|
|
|
2020-05-21 18:46:47 +00:00
|
|
|
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");
|
2020-05-22 15:54:33 +00:00
|
|
|
console.log( routes.log)
|
|
|
|
app.get('/log/:id', routes.log);
|
2020-05-15 23:24:56 +00:00
|
|
|
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}`);
|
|
|
|
});
|