Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cloud): soffit form deploy #704

Merged
merged 7 commits into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 0 additions & 100 deletions cloud/classic/soffit-form/compose.yml

This file was deleted.

3 changes: 0 additions & 3 deletions cloud/classic/soffit-form/deploy.sh

This file was deleted.

13 changes: 0 additions & 13 deletions cloud/classic/soffit-form/env/example.env

This file was deleted.

71 changes: 70 additions & 1 deletion cloud/classic/soffit-pwa/compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,75 @@ services:
labels:
traefik.enable: true
traefik.port: 80
traefik.frontend.rule: Host:${PWA_DOMAIN}
traefik.frontend.rule: Host:${DOMAIN}
traefik.frontend.entryPoints: http, https
traefik.frontend.redirect.entryPoint: https

storage-server:
image: ghcr.io/alimd/storage-server:${STORAGE_SERVER_VERSION:-next}

cpu_shares: 1024
mem_limit: 256m

stop_grace_period: 30s

restart: unless-stopped

networks:
internal:
aliases:
- '${APP_ID}-storage-server'

environment:
- STORAGE_PATH=/storage
- ACCESS_TOKEN=${STORAGE_TOKEN}
- ALWATR_DEBUG=${STORAGE_SERVER_DEBUG:-}

volumes:
- type: bind
source: ./_data/storage
target: /storage
bind:
create_host_path: true

logging:
driver: json-file
options:
max-size: '10m'
max-file: '2'

form-registration:
image: ghcr.io/alimd/form-registration:${FORM_REGISTRATION_VERSION:-next}

cpu_shares: 1024
mem_limit: 256m

restart: unless-stopped

networks:
internal:
alwatr-public-network:

depends_on:
- storage-server

environment:
- STORAGE_HOST=${APP_ID}-storage-server
- STORAGE_PORT=80
- STORAGE_NAME=${FORM_REGISTRATION_STORAGE_NAME}
- STORAGE_TOKEN=${STORAGE_TOKEN}
- ACCESS_TOKEN=${FORM_REGISTRATION_TOKEN}
- ALWATR_DEBUG=${FORM_REGISTRATION_DEBUG:-}

logging:
driver: json-file
options:
max-size: '10m'
max-file: '2'

labels:
traefik.enable: true
traefik.port: 80
traefik.frontend.rule: Host:${DOMAIN}; Path:/api
traefik.frontend.entryPoints: http, https
traefik.frontend.redirect.entryPoint: https
16 changes: 12 additions & 4 deletions cloud/classic/soffit-pwa/env/example.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
U2FsdGVkX1/XLv/cJZgBXKSOMQEV/GgZ4TxQbEhx4SOiY0y6KHFM+4RrW4UUOehh
yFisx7apY3qUiwAw8GpOzOQQZ4ciVt61ZewMK973ujmQnNgdDRN78AXaeIbujhtQ
p63YL5HLF6feDqLUW3VUo/AEgTuSDw6xrC10OIDbfmEsUQaoyL6gGOub5Atz60UG
DsGIL4FfFcP2TgysU+CCaLV89/Ut7/TpD992R+0eaNM=
U2FsdGVkX1/ePxXmD/c3Aim7yG8eNG/4+sXKXGlZGMmj7rnyI/jUmdZx51JjSlxi
YeiiPaYwDEdc9VkYR3C5QULdlPOnEQ/f1073+AUgMsOnT0qMSldf40TT+mSlYY3Q
C1OWAJUUmq2KTU2OG2quQ6QFNqVwEPY2NHzpldPIQ7k2czg5m/ZsA0+Pb53dIVj0
uH17sGyDSdIUyImjbn9zr7XRqoqakDOpQSfFzZJNCFsmEQ9IXQ8gOUIRjfapGfXE
rpQ8es1m1yomUZ+HcKIf+ETxVjkfp9FMIZX6PUh59RdhDC3fghfHD6UwUtl98S+Q
3Hw9AtCx1jjVhJb/Tml4HnhOARTMh633qDRQjHG83nRLtt1M96xOybfrt9Fo3lpB
v8kczzWZmfmM2gKdUVnA6Y7bkHHOPaOdGoESudo9KdkJNqTIk+YqKZ3OY93PdVa5
2GmykiHY2c6MFD7k0cCI7s9U1nZ0wYURXBQaEeUis72sZSBEOsi9qyUERTvk94rq
WAPLEdMtSVoXbKlioYJAlbpE85iUi6TCDqPPJa7duc2DsIjxv9WlbNirA8mYYmv+
2aHkqI8dsIOC3MCaWnt66cLyfT5TYdHm8GrpKmJSAvwRUugpsMtcvUJbbtltnRf9
l6cQk8fjqnGgL363ZUAqz7sPXg/TeOZqogr7mYnhoZW8VRHPJB2ewM131jHEVN/j
ggkgjzrO0K9/HFZ8PZlrzA==
5 changes: 4 additions & 1 deletion core/nano-server/src/nano-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,15 @@ export class AlwatrNanoServer {
*/
export class AlwatrConnection {
static versionPattern = new RegExp('^/v[0-9]+');
static apiPattern = new RegExp('^/api');

/**
* Request URL.
*/
readonly url = new URL(
(this.incomingMessage.url ?? '').replace(AlwatrConnection.versionPattern, ''),
(this.incomingMessage.url ?? '')
.replace(AlwatrConnection.apiPattern, '')
.replace(AlwatrConnection.versionPattern, ''),
'http://localhost/',
);

Expand Down
19 changes: 9 additions & 10 deletions services/form-registration/demo.http
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
@apiUrl = http://127.0.0.1:8000
@apiVersion = v0
@token = YOUR_SECRET_TOKEN

### home
GET {{apiUrl}}/
GET {{apiUrl}}/api/v0

### Add new form
PUT {{apiUrl}}/form/
PUT {{apiUrl}}/api/v0/form/
Authorization: Bearer {{token}}
Content-Type: application/json

Expand All @@ -17,31 +16,31 @@ Content-Type: application/json
}

### Get storage
GET {{apiUrl}}/form/?storage
GET {{apiUrl}}/form/v0/storage
Authorization: Bearer {{token}}



### === Test other routes and errors ===

### Page Home
GET {{apiUrl}}/{{apiVersion}}
GET {{apiUrl}}/v0

### Page 404 (wrong path)
GET {{apiUrl}}/{{apiVersion}}/jafang
GET {{apiUrl}}/v0/jafang

### Page 404 (wrong method)
POST {{apiUrl}}/{{apiVersion}}
POST {{apiUrl}}/v0

### Page health
GET {{apiUrl}}/{{apiVersion}}/health
GET {{apiUrl}}/v0/health

### empty body
POST {{apiUrl}}/{{apiVersion}}/echo
POST {{apiUrl}}/v0/echo
Content-Type: application/json

### invalid json
POST {{apiUrl}}/{{apiVersion}}/echo
POST {{apiUrl}}/v0/echo
Content-Type: application/json

{
Expand Down
2 changes: 1 addition & 1 deletion services/form-registration/src/route/put.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {storageClient} from '../lib/storage.js';
import type {AlwatrConnection, AlwatrServiceResponse} from '@alwatr/nano-server';
import type {AlwatrDocumentObject} from '@alwatr/type';

nanoServer.route('PUT', '/', setForm);
nanoServer.route('PUT', '/form/', setForm);

async function setForm(connection: AlwatrConnection): Promise<AlwatrServiceResponse> {
logger.logMethod('setForm');
Expand Down
2 changes: 1 addition & 1 deletion services/form-registration/src/route/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {storageClient} from '../lib/storage.js';

import type {AlwatrConnection, AlwatrServiceResponse} from '@alwatr/nano-server';

nanoServer.route('GET', '/storage', getFormStorage);
nanoServer.route('GET', '/form/storage', getFormStorage);

async function getFormStorage(connection: AlwatrConnection): Promise<AlwatrServiceResponse> {
logger.logMethod('getFormStorage');
Expand Down
2 changes: 1 addition & 1 deletion ui/demo-pwa/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@alwatr/ui-demo-pwa",
"version": "0.28.0",
"version": "0.28.0-prv2",
"description": "Alwatr Progressive Web Application Demo.",
"type": "module",
"author": "S. Ali Mihandoost <ali.mihandoost@gmail.com> (https://ali.mihandoost.com)",
Expand Down
2 changes: 1 addition & 1 deletion uniquely/soffit-pwa/res/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
window.appConfig = {
api: 'http://localhost:8000',
api: '/api/v0',
token: 'YOUR_SECRET_TOKEN',
};
2 changes: 1 addition & 1 deletion uniquely/soffit-pwa/src/lottery-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class AlwatrLotteryForm extends AlwatrSmartElement {
try {
await serviceRequest({
method: 'PUT',
url: config.api + '/',
url: config.api + '/form/',
token: config.token,
bodyJson,
});
Expand Down