Skip to content

Commit

Permalink
app.maffin.io initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
argaen committed Jun 27, 2023
0 parents commit 99fb567
Show file tree
Hide file tree
Showing 206 changed files with 49,958 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "npm" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "daily"
open-pull-requests-limit: 20
29 changes: 29 additions & 0 deletions .github/workflows/backend-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Backend CI

on: [push]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.17.0]

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'

- name: Install dependencies
run: yarn stocker:install

- name: Lint
run: yarn stocker:lint

- name: Test
run: yarn stocker:test
29 changes: 29 additions & 0 deletions .github/workflows/frontend-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Frontend CI

on: [push]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.17.0]

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'

- name: Install dependencies
run: yarn

- name: Build # includes lint
run: yarn maffin:build

- name: Test
run: yarn maffin:test --coverage
49 changes: 49 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
**/coverage

# next
.next
.vscode

# production
/build

account.gz*

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

#amplify-do-not-edit-begin
amplify/\#current-cloud-backend
amplify/.config/local-*
amplify/logs
amplify/mock-data
amplify/backend/amplify-meta.json
amplify/backend/.temp
build/
dist/
node_modules/
awsconfiguration.json
amplifyconfiguration.json
amplifyconfiguration.dart
amplify-build-config.json
amplify-gradle-config.json
amplifytools.xcconfig
.secret-*
**.sample
#amplify-do-not-edit-end
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v16.17.0
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# maffin.io

# Developing

If you want to add a new user, before starting with the installation you will need few steps:

1. [new maintainers only] Ask a maintainer for the AWS keys and credentials so you can interact with local amplify cli and access AWS console respectively
2. Add the user gmail account to the google console as a test user (for now)


## Installation

Run `nvm use` to set the correct node version.

```
yarn # Install frontend dependencies
yarn stocker:install # Install backend dependencies
```

If not installed yet, install amplify cli with `npm install -g @aws-amplify/cli`. Then if it's your first time, you'll have to pull the amplify project:

> Make sure to select your AWS profile credentials with `export AWS_PROFILE=maffin`
```
10:56 $ amplify pull
? Select the authentication method you want to use: AWS access keys
? accessKeyId: ******************** # credentials from maffin account
? secretAccessKey: ****************************************
? region: eu-central-1
? Which app are you working on? dkycpktllbi8x
Backend environment 'master' found. Initializing...
? Choose your default editor: Vim (via Terminal, macOS only)
? Choose the type of app that you're building javascript
Please tell us about your project
? What javascript framework are you using react
? Source Directory Path: src
? Distribution Directory Path: build
? Build Command: yarn build
? Start Command: yarn start
✖ Failed to sync UI components
? Do you plan on modifying this backend? Yes
```

## Running

Run stocker with `yarn stocker:start` and then the frontend with `yarn maffin:start:`.

## Deploying

The project is deployed automatically everytime there is a merge to master using Amplify pipeline.
23 changes: 23 additions & 0 deletions amplify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: 1
backend:
phases:
build:
commands:
- '# Execute Amplify CLI with the helper script'
- amplifyPush --simple
frontend:
phases:
preBuild:
commands:
- yarn install
build:
commands:
- rm -rf .next/
- yarn maffin:build
artifacts:
baseDirectory: .next
files:
- '**/*'
cache:
paths:
- node_modules/**/*
17 changes: 17 additions & 0 deletions amplify/.config/project-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"providers": [
"awscloudformation"
],
"projectName": "maffinapp",
"version": "3.1",
"frontend": "javascript",
"javascript": {
"framework": "react",
"config": {
"SourceDir": "src",
"DistributionDir": "build",
"BuildCommand": "yarn build",
"StartCommand": "yarn maffin:start"
}
}
}
19 changes: 19 additions & 0 deletions amplify/backend/api/stocker/cli-inputs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version": 1,
"paths": {
"/api/prices/live": {
"name": "/api/prices/live",
"lambdaFunction": "stockerlambda",
"permissions": {
"setting": "open"
}
},
"/api/funds/{isin}": {
"name": "/api/funds/{isin}",
"lambdaFunction": "stockerlambda",
"permissions": {
"setting": "open"
}
}
}
}
44 changes: 44 additions & 0 deletions amplify/backend/backend-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"api": {
"stocker": {
"dependsOn": [
{
"attributes": [
"Name",
"Arn"
],
"category": "function",
"resourceName": "stockerlambda"
}
],
"providerPlugin": "awscloudformation",
"service": "API Gateway"
}
},
"auth": {},
"function": {
"stockerlambda": {
"build": true,
"providerPlugin": "awscloudformation",
"service": "Lambda"
}
},
"parameters": {
"AMPLIFY_function_stockerlambda_deploymentBucketName": {
"usedBy": [
{
"category": "function",
"resourceName": "stockerlambda"
}
]
},
"AMPLIFY_function_stockerlambda_s3Key": {
"usedBy": [
{
"category": "function",
"resourceName": "stockerlambda"
}
]
}
}
}
6 changes: 6 additions & 0 deletions amplify/backend/function/stockerlambda/amplify.state
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"pluginId": "amplify-nodejs-function-runtime-provider",
"functionRuntime": "nodejs",
"useLegacyBuild": true,
"defaultEditorFile": "src/app.js"
}
6 changes: 6 additions & 0 deletions amplify/backend/function/stockerlambda/custom-policies.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"Action": [],
"Resource": []
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"lambdaLayers": []
}
67 changes: 67 additions & 0 deletions amplify/backend/function/stockerlambda/src/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const cors = require('cors');
const express = require('express');
const bodyParser = require('body-parser');
const awsServerlessExpressMiddleware = require('aws-serverless-express/middleware');

const yahoo = require('./yahoo');
const helpers = require('./helpers');

const app = express()
app.use(bodyParser.json())
app.use(awsServerlessExpressMiddleware.eventContext())


const ALLOWED_ORIGINS = [
'http://localhost:3000',
'https://app.maffin.io',
];

app.use(cors({
origin: (origin, callback) => {
if (
ALLOWED_ORIGINS.indexOf(origin) !== -1
|| origin.match(/https:\/\/.*d199ayutgsrlxn\.amplifyapp\.com/g)
) {
callback(null, true);
} else {
callback(new Error('Not allowed by CORS'));
}
}
}));

app.get('/api/prices/live', async (req, res) => {
let tickers = req.query.ids;
if (!tickers) {
res.status(400).json({
error: 'IDS_REQUIRED',
description: 'You need to pass \'ids\' queryparam to select specific quotes',
});
return;
}

tickers = tickers.split(',');

const result = {};
const promises = [];

async function callAndSave(ticker) {
price = await yahoo.getLiveSummary(ticker);
result[ticker] = price;
}

try {
tickers.forEach(ticker => promises.push(callAndSave(ticker)));
await Promise.all(promises);
} catch (error) {
console.log(error);
res.status(500).json({
error: 'UNKNOWN_ERROR',
description: 'Failed to retrieve prices',
});
return;
}

res.json(result);
});

module.exports = app;
12 changes: 12 additions & 0 deletions amplify/backend/function/stockerlambda/src/errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class HTTPError extends Error {
constructor(message, status, code) {
super(message);
this.message = message;
this.status = status;
this.code = code;
}
}

module.exports = {
HTTPError,
};
7 changes: 7 additions & 0 deletions amplify/backend/function/stockerlambda/src/event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"httpMethod": "GET",
"path": "/api/prices/live",
"queryStringParameters": {
"ids": "IAG.MC,AIR.PA"
}
}
Loading

0 comments on commit 99fb567

Please sign in to comment.