Here's one process.
In this case we'll just add an API, and keep using Firebase (or any JamStack host) for our FrontEnd.
Add server
folder to your project
Put your APIs, SQL commands, ETL, processing, etc here.Let's create a super simple server using NestJS
import * as express from 'express'; // import { log } from './log'; // import { API } from './api'; import { registerRoutes } from './routes'; import * as compression from 'compression'; const connection = API.factory(); const app: express.Express = express(); const mode = app.get('env'); connection.then((api) => { // console.log('DB connection is ready.'); if (mode === 'process') { setTimeout(() => api.process(), 1000); } else if (mode === 'development') { setInterval(() => api.process(false),15000); } if(mode !== 'process') { const port = mode == 'production' ? 11670 : mode == 'staging' ? 11671 : 11671; // const credentials = require("./lib/credentials").credentials[mode]; // Trust the proxy app.set('trust proxy', 'loopback, linklocal, uniquelocal'); app.use(function (req, res, next) { res.header('Access-Control-Allow-Origin', '*'); res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept'); res.header('Access-Control-Allow-Methods', 'OPTIONS, GET, POST, DELETE'); if ('OPTIONS' == req.method) { res.sendStatus(200); } else { log(`${req.ip} ${req.method} ${req.url}`); next(); } }); app.use(compression()); registerRoutes(app); // Send SPA via public app.use(express.static('dist')); app.use((req, res) => res.sendFile(`${__dirname}/dist/index.html`)); app.listen(port, '127.0.0.1', function () { console.log(`BundleSizeServer Listening on ${port} in ${mode} mode.`); }); }
Configure a server
I'm going to use Apache with a reverse proxy to a local ts-node process.Here's my virtual host setup. Just pick a high port, any port (11670 in this case).
<VirtualHost *:80> ServerName api.money.fluin.io ServerAdmin money@fluin.io ProxyPreserveHost On ProxyVia Full <Proxy *> Options -Indexes +FollowSymLinks </Proxy> <Location "/"> ProxyPass http://127.0.0.1:11670/ ProxyPassReverse http://127.0.0.1:11670/ </Location> ErrorLog /var/www/logs/api.money.fluin.io-error.log CustomLog /var/www/logs/api.money.fluin.io-access.log combined </VirtualHost>