Skip to content

Instantly share code, notes, and snippets.

@pivanov
Created March 23, 2018 10:57
Show Gist options
  • Save pivanov/16a5f267db12f1953ae7b4a771374f8d to your computer and use it in GitHub Desktop.
Save pivanov/16a5f267db12f1953ae7b4a771374f8d to your computer and use it in GitHub Desktop.
This is your `cloud/app.js` file
/*
* Advanced Cloud Code Example
*/
const connect = require('connect')
const serveStatic = require('serve-static')
const vhost = require('vhost')
const express = require('express');
const app = express();
app.get('/hello-advanced', function (req, res) {
const mainAppHost = req.headers.host.includes('mainapp.local');
const userAppHost = req.headers.host.includes('userapp.local');
if(mainAppHost) {
res.send(`Hello from mainApp on host ${req.headers.host}`);
} else if(userAppHost) {
res.send(`Hello from userApp on host ${req.headers.host}`);
} else {
res.send("Hello from SashiDo's Advanced Cloud Code");
}
});
// MainApp
var mainApp = connect();
mainApp.use(serveStatic('public/mainapp'))
app.use(vhost('mainapp.local', mainApp))
// UserApp
var userApp = connect();
userApp.use(serveStatic('public/userapp'))
app.use(vhost('userapp.local', userApp))
module.exports = app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment