Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import * as express from 'express';
- import * as subdomain from 'express-subdomain'; // See subdomain package
- import { UserRoutes } from './User';
- import { AuthRoutes } from './Auth';
- export class Router {
- static routeAPI(app) {
- const router = express.Router();
- router.use((req, res, next) => {
- res.header('Access-Control-Allow-Origin', '*');
- res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,PATCH');
- res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
- next();
- });
- AuthRoutes.route(router);
- UserRoutes.route(router);
- app.use(subdomain('api', router)); // App uses subdomain
- }
- }
- server {
- listen 80;
- server_name api.localhost;
- return 301 https://$host$request_uri;
- }
- server {
- listen 443 ssl;
- server_name api.localhost;
- access_log /var/log/nginx/api.localhost.log;
- ssl_certificate /etc/letsencrypt/live/api.localhost/fullchain.pem;
- ssl_certificate_key /etc/letsencrypt/live/api.localhost/privkey.pem;
- ssl_stapling on;
- ssl_stapling_verify on;
- location / {
- proxy_pass http://localhost:8080;
- proxy_http_version 1.1;
- proxy_set_header Upgrade $http_upgrade;
- proxy_set_header Connection 'upgrade';
- proxy_set_header Host $host;
- proxy_cache_bypass $http_upgrade;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement