Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
225 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
const { mergeDeep, all } = require('../../src/utils') | ||
|
||
const Component = require('../Component/serverless') | ||
const Socket = require('../Socket/serverless') | ||
const Website = require('../Website/serverless') | ||
|
||
// private helper functionn | ||
const getConfig = (inputs) => { | ||
const defaults = { | ||
name: 'realtimeApp', | ||
stage: 'dev', | ||
description: 'Realtime App', | ||
region: 'us-east-1', | ||
frontend: { | ||
code: './frontend', | ||
assets: '.', | ||
envFileLocation: './src/env.js', | ||
env: {}, | ||
buildCmd: null | ||
}, | ||
backend: { | ||
code: './backend', | ||
memory: 512, | ||
timeout: 10, | ||
env: {} | ||
} | ||
} | ||
|
||
const config = mergeDeep(defaults, inputs) | ||
|
||
config.backend.name = `${config.name}-${config.stage}` | ||
config.backend.description = config.description | ||
config.backend.credentials = config.credentials | ||
config.backend.region = config.region | ||
|
||
config.frontend.name = `${config.name}-${config.stage}` | ||
config.frontend.credentials = config.credentials | ||
config.frontend.region = config.region | ||
|
||
return config | ||
} | ||
|
||
class RealtimeApp extends Component { | ||
async default(inputs = {}) { | ||
this.cli.status('Deploying Realtime App') | ||
const config = getConfig(inputs) | ||
|
||
const website = new Website(`${this.id}.website`) | ||
const socket = new Socket(`${this.id}.socket`) | ||
|
||
// deploy in parallel like a boss! | ||
const outputs = await all([website(config.frontend), socket(config.backend)]) | ||
const websiteOutputs = outputs[0] | ||
const socketOutputs = outputs[1] | ||
|
||
this.cli.success('Realtime App Deployed') | ||
this.cli.log('') | ||
this.cli.output('Socket URL', ` ${socketOutputs.websockets.url}`) | ||
this.cli.output('Website URL', `${websiteOutputs.url}`) | ||
|
||
// this high level component doesn't need to save any state! | ||
|
||
return { website: websiteOutputs, socket: socketOutputs } | ||
} | ||
|
||
async remove() { | ||
// this remove function just calls remove on the child components | ||
// it doesn't even need any inputs at all since all is available in children state! | ||
this.cli.status('Removing Realtime App') | ||
|
||
const website = new Website(`${this.id}.website`) | ||
const socket = new Socket(`${this.id}.socket`) | ||
|
||
const outputs = await all([website.remove(), socket.remove()]) | ||
|
||
const websiteOutputs = outputs[0] | ||
const socketOutputs = outputs[1] | ||
|
||
this.cli.success('Realtime App Removed') | ||
|
||
return { website: websiteOutputs, socket: socketOutputs } | ||
} | ||
} | ||
|
||
module.exports = RealtimeApp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.