Skip to content

Commit

Permalink
Добавляет префикс "restapi" для импорта (#25)
Browse files Browse the repository at this point in the history
* [fix] Fix geo property creating error

* [fix] Add prefix for csv import

* fix: migrations in dev build

* [feat] Add API_PREFIX env variable

* [ref] Use separated file for API_PREFIX

* fix: api prefix in build

Co-authored-by: dice4x4 <[email protected]>
  • Loading branch information
kantegory and dice4x4 authored Jul 6, 2022
1 parent 2c15caf commit 80da033
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ DB_DIALECT=postgres
SERVER_PORT=8000
ACCESS_TOKEN_LIFETIME=300000
REFRESH_TOKEN_LIFETIME=3600000
API_PREFIX=/restapi/v1
2 changes: 2 additions & 0 deletions .github/workflows/deploy-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ env:
SERVER_PORT: 8000
ACCESS_TOKEN_LIFETIME: 300000
REFRESH_TOKEN_LIFETIME: 3600000
API_PREFIX: /restapi/v1

jobs:
deploy:
Expand Down Expand Up @@ -80,6 +81,7 @@ jobs:
-e POSTGRES_DB=${{ env.POSTGRES_DB }} \
-e DB_PORT=${{ env.DB_PORT }} -e DB_HOST=${{ env.DB_HOST }} \
-e DB_DIALECT=${{ env.DB_DIALECT }} \
-e API_PREFIX=${{ env.API_PREFIX }} \
-e SERVER_PORT=${{ env.SERVER_PORT }} \
-e ACCESS_TOKEN_LIFETIME=${{ env.ACCESS_TOKEN_LIFETIME }} \
-e REFRESH_TOKEN_LIFETIME=${{ env.REFRESH_TOKEN_LIFETIME }} \
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/deploy-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ env:
POSTGRES_DB: ${{ secrets.POSTGRES_DB_STAGE }}
DB_PORT: ${{ secrets.DB_PORT_STAGE }}
DB_HOST: ${{ secrets.DB_HOST_STAGE }}
API_PREFIX: /restapi/v1

jobs:
deploy:
Expand All @@ -47,6 +48,7 @@ jobs:
-e POSTGRES_DB=${{ env.POSTGRES_DB }} \
-e DB_PORT=${{ env.DB_PORT }} -e DB_HOST=${{ env.DB_HOST }} \
-e DB_DIALECT=${{ env.DB_DIALECT }} \
-e API_PREFIX=${{ env.API_PREFIX }} \
-e SERVER_PORT=${{ env.SERVER_PORT }} \
-e ACCESS_TOKEN_LIFETIME=${{ env.ACCESS_TOKEN_LIFETIME }} \
-e REFRESH_TOKEN_LIFETIME=${{ env.REFRESH_TOKEN_LIFETIME }} \
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ services:
- 8000:8000
depends_on:
- db
env_file:
- .env
3 changes: 2 additions & 1 deletion src/admin/components/import-action-component.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react'
import { API_PREFIX } from "../../configs/constants"

const ImportAction = () => {
async function submitForm(form: HTMLFormElement) {
const formData = new FormData(form)

const response = await fetch(
'/v1/admin/import-csv',
`${API_PREFIX}/admin/import-csv`,
{
method: 'POST',
body: formData
Expand Down
5 changes: 5 additions & 0 deletions src/configs/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const API_PREFIX = process.env.API_PREFIX || "/restapi/v1"

export {
API_PREFIX
}
6 changes: 5 additions & 1 deletion src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,21 @@ import FilledPropertyService from "../services/cards/FilledProperty"
import GeoPropertyService from "../services/cards/GeoProperty"
import DateCatalogService from "../services/dates/DateCatalog"
import OrganizationService from "../services/organizations/Organization"
import { API_PREFIX } from "../configs/constants"

class App {
public port: string

readonly app: express.Application
readonly server: Server
readonly sequelize: Sequelize
readonly apiPrefix: string

constructor(port = '8000') {
this.port = process.env.SERVER_PORT || port

this.apiPrefix = API_PREFIX

this.app = this.createApp()
this.server = createServer(this.app)
this.sequelize = sequelize
Expand All @@ -53,7 +57,7 @@ class App {
app.use(cors())
app.use(bodyParser.json())
app.use(passport.initialize())
app.use('/v1', getRouter(this.provideControllers()))
app.use(`${this.apiPrefix}/`, getRouter(this.provideControllers()))
app.use('/admin', adminRoutes)
if (process.env.NODE_ENV != 'production') {
app.use('/swagger', docsRoutes)
Expand Down
1 change: 0 additions & 1 deletion src/routes/v1/cards/CsvImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { parse } from "csv-parse/sync"
import fs from "fs"
import Card, { FilledPropertyCard } from "../../../models/cards/Card"
import FilledProperty from "../../../models/cards/FilledProperty"
import GeoProperty from "../../../models/cards/GeoProperty"
import Property from "../../../models/cards/Property"

class JulianDate {
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"strictPropertyInitialization": false,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"jsx": "react"
"jsx": "react",
"allowJs": true
}
}

0 comments on commit 80da033

Please sign in to comment.