-
Notifications
You must be signed in to change notification settings - Fork 1
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
20 changed files
with
272 additions
and
29 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 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,22 @@ | ||
FROM node:20.12.2 as dist | ||
WORKDIR /tmp/ | ||
COPY package.json package-lock.json tsconfig.json ./ | ||
RUN npm ci --force | ||
COPY projects/exchange/ projects/exchange/ | ||
COPY projects/meta/ projects/meta/ | ||
RUN npm run exchange:build | ||
|
||
FROM node:20.12.2-slim as node_modules | ||
WORKDIR /tmp/ | ||
COPY package.json package-lock.json ./ | ||
RUN npm install --production --force | ||
|
||
FROM node:20.12.2 | ||
RUN npm install pm2 -g | ||
RUN mkdir -p /var/app | ||
WORKDIR /var/app | ||
COPY --from=node_modules /tmp/node_modules ./node_modules | ||
COPY --from=dist /tmp/dist/exchange/ ./dist/ | ||
COPY projects/exchange/docker-entrypoint.sh ./ | ||
EXPOSE 3080 | ||
ENTRYPOINT ["./docker-entrypoint.sh"] |
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,51 @@ | ||
import fastify from 'fastify'; | ||
import {existsSync, readFileSync, writeFileSync, mkdirSync} from 'fs'; | ||
import {resolve} from 'path'; | ||
import {Api_GetProject} from '../meta/api'; | ||
import {formatExchangeFile} from '../meta/format-exchange-file'; | ||
|
||
const app = fastify({ | ||
logger: true, | ||
bodyLimit: 10 * 10000, // X * MB | ||
}); | ||
|
||
const projectsPath = resolve(__dirname, 'projects'); | ||
if (!existsSync(projectsPath)) { | ||
mkdirSync(projectsPath); | ||
} | ||
|
||
app.register(async app => { | ||
app.post<{Body: Api_GetProject; Params: {project: string; branch: string}}>( | ||
'/api/project/save/:project/:branch', | ||
async (req) => { | ||
const path = resolve(projectsPath, compileProjectFilename(req.params.project, req.params.branch)); | ||
writeFileSync(path, JSON.stringify(req.body)); | ||
return true; | ||
}); | ||
|
||
app.post<{Params: {project: string; branch: string}}>( | ||
'/api/project/load/:project/:branch', | ||
async (req) => { | ||
const path = resolve(projectsPath, compileProjectFilename(req.params.project, req.params.branch)); | ||
if (!existsSync(path)) { | ||
throw new Error(`File for project/branch not found`); | ||
} | ||
return JSON.parse(readFileSync(path, {encoding: 'utf8'})); | ||
}); | ||
}); | ||
|
||
app.register(require('fastify-disablecache')); | ||
app.register(require('@fastify/cors')); | ||
|
||
app.listen({ | ||
port: 3080, | ||
host: '0.0.0.0', | ||
}).then(async (url) => { | ||
app.log.info(`🗃️ ngxe exchange working on ${url}`); | ||
}).catch(err => { | ||
console.error(err); | ||
}) | ||
|
||
function compileProjectFilename(project: string, branch: string) { | ||
return `proj_${formatExchangeFile(project)}-branch_${formatExchangeFile(branch)}`; | ||
} |
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,3 @@ | ||
#!/bin/sh | ||
|
||
pm2-docker ./dist/exchange/app.js --name='app' |
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,2 @@ | ||
* | ||
!.gitignore |
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,27 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "node16", | ||
"target": "ES2022", | ||
"emitDecoratorMetadata": true, | ||
"experimentalDecorators": true, | ||
"declaration": false, | ||
"incremental": true, | ||
"outDir": "../../dist/exchange", | ||
"baseUrl": "./", | ||
"resolveJsonModule": true, | ||
"strict": true, | ||
"alwaysStrict": true, | ||
"allowJs": true, | ||
"esModuleInterop": true, | ||
"typeRoots": ["node_modules/@types"], | ||
"skipLibCheck": true, | ||
"strictPropertyInitialization": false, | ||
"noImplicitAny": false, | ||
"allowSyntheticDefaultImports": true, | ||
"lib": ["ES2023"] | ||
}, | ||
"exclude": [ | ||
"node_modules", | ||
"dist" | ||
] | ||
} |
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,3 @@ | ||
export function formatExchangeFile(file: string = '') { | ||
return file.replace(/[^a-z0-9]/gi, '_'); | ||
} |
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
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,23 @@ | ||
import { HttpClient } from '@angular/common/http'; | ||
import { Injectable } from '@angular/core'; | ||
import { Observable } from 'rxjs'; | ||
import { Api_Error, Api_GetProject } from '../../../meta/api'; | ||
import {environment} from '../environments/environment'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class ExchangeService { | ||
constructor( | ||
private http: HttpClient, | ||
) { | ||
} | ||
|
||
loadProject({project, branch}: {project: string; branch: string}): Observable<Api_GetProject | Api_Error> { | ||
return this.http.post<Api_GetProject | Api_Error>(`${environment.exchangeUrl}/api/project/load/${project}/${branch}`, {}); | ||
} | ||
|
||
saveProject({project, branch, body}: {project: string; branch: string, body: any}): Observable<true | Api_Error> { | ||
return this.http.post<true | Api_Error>(`${environment.exchangeUrl}/api/project/save/${project}/${branch}`, body); | ||
} | ||
} |
Oops, something went wrong.