app.get('/api/v1', function middleware (req, res, next) {
// this function is middleware
req.locals.middlewareObject = { name: 'middleware', called: true }
next()
}, function otherMiddleware (req, res, next) {
// this function is middleware too
return res.json(req.locals.middlewareObject)
})
Какие должны быть мои действия?
var path = require('path');
var express = require('express');
var app = express();
app.use(express.static(path.join(__dirname, './public'))); // если сайт лежит в папке public в корне проекта
app.listen(3000, function () {
console.log('Example app listening on port 3000!');
});
user www-data;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 1024;
multi_accept on;
}
http {
sendfile on;
access_log /root/projects/logs/domen.ru/access.log;
error_log /root/projects/logs/domen.ru/error.log crit;
gzip on;
gzip_disable "msie6";
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript;
server {
listen 80;
server_name domen.ru www.domen.ru;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
server_name domen.ru www.domen.ru;
keepalive_timeout 60;
keepalive_requests 50;
ssl_certificate /root/domen.ru.ssl/domen.ru.crt;
ssl_certificate_key /root/domen.ru.ssl/domen.ru.key;
ssl_session_cache shared:SSL:30m;
ssl_session_timeout 1h;
ssl_stapling on;
resolver 8.8.8.8;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 SSLv2 SSLv3;
ssl_prefer_server_ciphers on;
ssl_ciphers "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH+aRSA+RC4 EECDH EDH+aRSA !RC4 !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS";
ssl_dhparam /root/domen.ru.ssl/domen.ru.dh4096.pem;
add_header Strict-Transport-Security 'max-age=604800';
location / {
proxy_pass http://localhost:8080;
#proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
client_max_body_size 10m;
client_body_buffer_size 256k;
proxy_connect_timeout 120;
proxy_send_timeout 120;
proxy_read_timeout 120;
proxy_buffer_size 128k;
proxy_buffers 32 128k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
}
}
}
var StaticPath = path.join(__dirname, '../build');
// Включаем оптимизацию изображений
var optimus = require('connect-image-optimus');
app.use(optimus(StaticPath));
app.use(express.static(StaticPath));