chore: remove proxy service

This commit is contained in:
Karol Sójko 2023-02-24 08:14:17 +01:00
parent f638287213
commit 2d8919a079
No known key found for this signature in database
GPG key ID: D966F68E8A92F649
14 changed files with 0 additions and 274 deletions

View file

@ -1,22 +0,0 @@
name: Proxy Server
concurrency:
group: proxy_server
cancel-in-progress: true
on:
push:
tags:
- '*standardnotes/proxy-server*'
workflow_dispatch:
jobs:
call_server_application_workflow:
name: Server Application
uses: standardnotes/server/.github/workflows/common-server-application.yml@main
with:
service_name: proxy
workspace_name: "@standardnotes/proxy-server"
deploy_worker: false
package_path: packages/proxy
secrets: inherit

View file

@ -20,7 +20,6 @@ import '../src/Controller/v1/OfflineController'
import '../src/Controller/v1/FilesController'
import '../src/Controller/v1/SubscriptionInvitesController'
import '../src/Controller/v1/AuthenticatorsController'
import '../src/Controller/v1/ProxyController'
import '../src/Controller/v2/PaymentsControllerV2'
import '../src/Controller/v2/ActionsControllerV2'

View file

@ -1,18 +0,0 @@
import { Request, Response } from 'express'
import { inject } from 'inversify'
import { all, BaseHttpController, controller } from 'inversify-express-utils'
import TYPES from '../../Bootstrap/Types'
import { HttpServiceInterface } from '../../Service/Http/HttpServiceInterface'
@controller('/v1/proxy')
export class ProxyController extends BaseHttpController {
constructor(@inject(TYPES.HTTPService) private httpService: HttpServiceInterface) {
super()
}
@all('*', TYPES.AuthMiddleware)
async createToken(request: Request, response: Response): Promise<void> {
await this.httpService.callProxyServer(request, response, request.path.replace('/v1/proxy', ''), request.body)
}
}

View file

@ -1 +0,0 @@
dist

View file

@ -1,6 +0,0 @@
{
"extends": "../../.eslintrc",
"parserOptions": {
"project": "./linter.tsconfig.json"
}
}

View file

@ -1,40 +0,0 @@
# Change Log
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.1.6](https://github.com/standardnotes/server/compare/@standardnotes/proxy-server@1.1.5...@standardnotes/proxy-server@1.1.6) (2023-02-23)
### Bug Fixes
* **proxy:** make healthcheck endpoint accessible at all times ([b1122a3](https://github.com/standardnotes/server/commit/b1122a3da5d0fe02b80b91da5e96cffbad994ce2))
## [1.1.5](https://github.com/standardnotes/server/compare/@standardnotes/proxy-server@1.1.4...@standardnotes/proxy-server@1.1.5) (2023-02-22)
**Note:** Version bump only for package @standardnotes/proxy-server
## [1.1.4](https://github.com/standardnotes/server/compare/@standardnotes/proxy-server@1.1.3...@standardnotes/proxy-server@1.1.4) (2023-02-22)
**Note:** Version bump only for package @standardnotes/proxy-server
## [1.1.3](https://github.com/standardnotes/server/compare/@standardnotes/proxy-server@1.1.2...@standardnotes/proxy-server@1.1.3) (2023-02-22)
**Note:** Version bump only for package @standardnotes/proxy-server
## [1.1.2](https://github.com/standardnotes/server/compare/@standardnotes/proxy-server@1.1.1...@standardnotes/proxy-server@1.1.2) (2023-02-22)
**Note:** Version bump only for package @standardnotes/proxy-server
## [1.1.1](https://github.com/standardnotes/server/compare/@standardnotes/proxy-server@1.1.0...@standardnotes/proxy-server@1.1.1) (2023-02-22)
**Note:** Version bump only for package @standardnotes/proxy-server
# 1.1.0 (2023-02-22)
### Bug Fixes
* **proxy:** prevent from passing auth tokens to proxy destination ([91c70a5](https://github.com/standardnotes/server/commit/91c70a51a067c606afc3570764367a6d60910ce3))
### Features
* **proxy:** add proxy server ([dfe30d7](https://github.com/standardnotes/server/commit/dfe30d7f5e8598ec1886db0e061b7d593cc27e29))

View file

@ -1,17 +0,0 @@
FROM node:18.13.0-alpine
RUN apk add --update \
curl \
&& rm -rf /var/cache/apk/*
ENV NODE_ENV production
RUN corepack enable
COPY ./ /workspace
WORKDIR /workspace/packages/proxy
ENTRYPOINT [ "/workspace/packages/proxy/docker/entrypoint.sh" ]
CMD [ "start-web" ]

View file

@ -1,91 +0,0 @@
import * as http from 'http'
import * as https from 'https'
import * as path from 'path'
const MAX_IMAGE_SIZE = 10 * 1024 * 1024
const ENABLED = false
http
.createServer((req, res) => {
if (req.url === '/healthcheck') {
res.writeHead(200)
res.end()
return
}
if (!ENABLED) {
res.writeHead(404)
res.end()
return
}
res.setHeader('Access-Control-Allow-Origin', '*')
res.setHeader('Access-Control-Request-Method', '*')
res.setHeader('Access-Control-Allow-Methods', 'OPTIONS, GET')
res.setHeader('Access-Control-Allow-Headers', '*')
if (req.method === 'OPTIONS') {
res.writeHead(200)
res.end()
return
}
delete req.headers.authorization
delete req.headers['x-auth-token']
delete req.headers['x-auth-offline-token']
/** Remove / or // prefixes */
const target = (req.url as string).replace(/^\/+/, '')
try {
const url = new URL(target)
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
throw new Error('Invalid URL protocol')
}
if (url.hostname === '') {
throw new Error('Invalid URL hostname')
}
const ext = path.extname(url.pathname)
if (!['.jpg', '.jpeg', '.png', '.gif'].includes(ext)) {
res.writeHead(400)
res.end('Only image files can be proxied')
return
}
const library = url.protocol === 'http:' ? http : https
const proxyRequest = library
.get(url.href, (targetRes) => {
let totalSize = 0
targetRes.on('data', (chunk) => {
totalSize += chunk.length
if (totalSize > MAX_IMAGE_SIZE) {
proxyRequest.destroy(new Error('Image size exceeds the limit.'))
}
})
targetRes.on('end', () => {
const contentType = targetRes.headers['content-type']
if (!contentType || !contentType.startsWith('image/')) {
res.writeHead(400, { 'Content-Type': 'text/plain' })
res.end(`Invalid content type: ${contentType}`)
return
}
res.writeHead(targetRes.statusCode as number, targetRes.headers)
targetRes.pipe(res)
})
})
.on('error', (error) => {
res.writeHead(500)
res.end(`Error: ${error.message}`)
})
} catch (error) {
res.writeHead(500)
res.end(`Invalid URL: ${target} Error: ${error}`)
}
})
.listen(3000)

View file

@ -1,11 +0,0 @@
'use strict'
const path = require('path')
const pnp = require(path.normalize(path.resolve(__dirname, '../../..', '.pnp.cjs'))).setup()
const index = require(path.normalize(path.resolve(__dirname, '../dist/bin/server.js')))
Object.defineProperty(exports, '__esModule', { value: true })
exports.default = index

View file

@ -1,17 +0,0 @@
#!/bin/sh
set -e
COMMAND=$1 && shift 1
case "$COMMAND" in
'start-web' )
echo "[Docker] Starting Web..."
node docker/entrypoint-server.js
;;
* )
echo "Unknown command"
;;
esac
exec "$@"

View file

@ -1,4 +0,0 @@
{
"extends": "./tsconfig.json",
"exclude": ["dist"]
}

View file

@ -1,32 +0,0 @@
{
"name": "@standardnotes/proxy-server",
"version": "1.1.6",
"engines": {
"node": ">=18.0.0 <19.0.0"
},
"private": true,
"description": "Proxy Server",
"main": "dist/src/index.js",
"typings": "dist/src/index.d.ts",
"repository": "git@github.com:standardnotes/server.git",
"author": "Karol Sójko <karolsojko@standardnotes.com>",
"license": "AGPL-3.0-or-later",
"scripts": {
"clean": "rm -fr dist",
"build": "tsc --build",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"start": "yarn node dist/bin/server.js"
},
"dependencies": {
"newrelic": "^9.8.0"
},
"devDependencies": {
"@types/newrelic": "^9.4.0",
"@types/node": "^18.14.0",
"@typescript-eslint/eslint-plugin": "^5.48.2",
"eslint": "^8.32.0",
"eslint-plugin-prettier": "^4.0.0",
"typescript": "^4.8.4"
}
}

View file

@ -1,11 +0,0 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"composite": true,
"outDir": "./dist",
},
"include": [
"bin/**/*",
],
"references": []
}

View file

@ -53,9 +53,6 @@
{
"path": "./packages/predicates"
},
{
"path": "./packages/proxy"
},
{
"path": "./packages/revisions"
},