Skip to content

Commit

Permalink
first commit)
Browse files Browse the repository at this point in the history
  • Loading branch information
zgurea1 committed Jul 12, 2023
1 parent d2128ae commit aca3702
Show file tree
Hide file tree
Showing 30 changed files with 4,629 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
18 changes: 18 additions & 0 deletions .env.development.local.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ENV
NODE_ENV = development

# PORT
PORT = 3000

# LOG
LOG_FORMAT = dev
LOG_DIR = ../logs

# CORS
ORIGIN = http://localhost:9000
CREDENTIALS = true

# MSIGN
WSDL_URL = https://msign.staging.egov.md:8443/MSign.svc
MSING_API = https://msign.staging.egov.md
FRONTEND_URL = http://localhost:9000
18 changes: 18 additions & 0 deletions .env.production.local.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ENV
NODE_ENV = production

# PORT
PORT = 3000

# LOG
LOG_FORMAT = dev
LOG_DIR = ../logs

# CORS
ORIGIN = http://localhost:9000
CREDENTIALS = true

# MSIGN
WSDL_URL = https://msign.staging.egov.md:8443/MSign.svc
MSING_API = https://msign.staging.egov.md
FRONTEND_URL = http://localhost:9000
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/dist
18 changes: 18 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"parser": "@typescript-eslint/parser",
"extends": ["prettier", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"],
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {
"@typescript-eslint/explicit-member-accessibility": 0,
"@typescript-eslint/explicit-function-return-type": 0,
"@typescript-eslint/no-parameter-properties": 0,
"@typescript-eslint/interface-name-prefix": 0,
"@typescript-eslint/explicit-module-boundary-types": 0,
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-var-requires": "off"
}
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Certs
*.pem

# Runtime data
pids
*.pid
Expand Down
5 changes: 5 additions & 0 deletions .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"*.ts": [
"npm run lint"
]
}
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"printWidth": 150,
"tabWidth": 2,
"singleQuote": true,
"trailingComma": "all",
"semi": true,
"arrowParens": "avoid"
}
40 changes: 40 additions & 0 deletions .swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": false,
"dynamicImport": true,
"decorators": true
},
"transform": {
"legacyDecorator": true,
"decoratorMetadata": true
},
"target": "es2017",
"externalHelpers": false,
"keepClassNames": true,
"loose": false,
"minify": {
"compress": false,
"mangle": false
},
"baseUrl": "src",
"paths": {
"@/*": ["*"],
"@config": ["config"],
"@controllers/*": ["controllers/*"],
"@databases": ["databases"],
"@dtos/*": ["dtos/*"],
"@exceptions/*": ["exceptions/*"],
"@interfaces/*": ["interfaces/*"],
"@middlewares/*": ["middlewares/*"],
"@models/*": ["models/*"],
"@routes/*": ["routes/*"],
"@services/*": ["services/*"],
"@utils/*": ["utils/*"]
}
},
"module": {
"type": "commonjs"
}
}
12 changes: 12 additions & 0 deletions nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"watch": [
"src",
".env"
],
"ext": "js,ts,json",
"ignore": [
"src/logs/*",
"src/**/*.{spec,test}.ts"
],
"exec": "ts-node -r tsconfig-paths/register --transpile-only src/server.ts"
}
65 changes: 65 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"name": "typescirpt-msign-example",
"version": "1.0.0",
"description": "",
"author": "Alexandru Zgureanu",
"license": "MIT",
"scripts": {
"start": "npm run build && cross-env NODE_ENV=production node dist/server.js",
"dev": "cross-env NODE_ENV=development nodemon",
"build": "swc src -d dist --source-maps --copy-files",
"build:tsc": "tsc && tsc-alias",
"lint": "eslint --ignore-path .gitignore --ext .ts src/",
"lint:fix": "npm run lint -- --fix"
},
"dependencies": {
"compression": "^1.7.4",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"dotenv": "^16.3.1",
"envalid": "^7.3.1",
"express": "^4.18.1",
"express-rate-limit": "^6.7.0",
"express-session": "^1.17.3",
"helmet": "^7.0.0",
"hpp": "^0.2.3",
"https": "^1.0.0",
"lodash": "^4.17.21",
"morgan": "^1.10.0",
"multer": "^1.4.5-lts.1",
"soap": "^1.0.0",
"winston": "^3.9.0",
"winston-daily-rotate-file": "^4.7.1",
"xss": "^1.0.14"
},
"devDependencies": {
"@swc/cli": "^0.1.57",
"@swc/core": "^1.3.67",
"@types/compression": "^1.7.2",
"@types/cookie-parser": "^1.4.3",
"@types/cors": "^2.8.12",
"@types/express": "^4.17.13",
"@types/express-fileupload": "^1.4.1",
"@types/hpp": "^0.2.2",
"@types/morgan": "^1.9.3",
"@types/multer": "^1.4.7",
"@types/node": "^20.3.3",
"@typescript-eslint/eslint-plugin": "^5.61.0",
"@typescript-eslint/parser": "^5.61.0",
"cross-env": "^7.0.3",
"eslint": "^8.44.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^4.2.1",
"lint-staged": "^13.2.3",
"node-config": "^0.0.2",
"node-gyp": "^9.4.0",
"nodemon": "^2.0.22",
"prettier": "^2.8.8",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"tsc-alias": "^1.8.7",
"tsconfig-paths": "^4.2.0",
"tslib": "^2.6.0",
"typescript": "^5.1.6"
}
}
62 changes: 62 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import compression from 'compression';
import cookieParser from 'cookie-parser';
import cors from 'cors';
import express from 'express';
import helmet from 'helmet';
import hpp from 'hpp';
import morgan from 'morgan';
import { NODE_ENV, PORT, LOG_FORMAT, corsOptions } from '@config';
import { Routes } from '@interfaces/routes.interface';
import { ErrorMiddleware } from '@middlewares/error.middleware';
import { logger, stream } from '@utils/logger';
class App {
public app: express.Application;
public env: string;
public port: string | number;

constructor(routes: Routes[]) {
this.app = express();
this.env = NODE_ENV || 'development';
this.port = PORT || 3000;

this.initializeMiddlewares();
this.initializeRoutes(routes);
this.initializeErrorHandling();
}

public listen() {
this.app.listen(this.port, () => {
logger.info(`=================================`);
logger.info(`======= ENV: ${this.env} =======`);
logger.info(`🚀 App listening on the port ${this.port}`);
logger.info(`=================================`);
});
}

public getServer() {
return this.app;
}

private initializeMiddlewares() {
this.app.use(morgan(LOG_FORMAT, { stream }));
this.app.use(cors(corsOptions));
this.app.use(hpp());
this.app.use(helmet());
this.app.use(compression());
this.app.use(express.json());
this.app.use(express.urlencoded({ extended: true }));
this.app.use(cookieParser());
}

private initializeRoutes(routes: Routes[]) {
routes.forEach(route => {
this.app.use('/v1', route.router);
});
}

private initializeErrorHandling() {
this.app.use(ErrorMiddleware);
}
}

export default App;
Binary file added src/config/cert/invoce-example.pdf
Binary file not shown.
Empty file added src/config/cert/key.pem.example
Empty file.
Empty file added src/config/cert/pki.pem.example
Empty file.
25 changes: 25 additions & 0 deletions src/config/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { config } from 'dotenv';
import { readFileSync } from 'fs';
import { join } from 'path';
config({ path: `.env.${process.env.NODE_ENV || 'development'}.local` });

export const privateKey = readFileSync(join(__dirname, '/cert/key.pem'));
export const pkiCert = readFileSync(join(__dirname, '/cert/pki.pem'));
export const pdfBuffer = readFileSync(join(__dirname, '/cert/invoce-example.pdf'));

export const CREDENTIALS = process.env.CREDENTIALS === 'true';
export const { NODE_ENV, PORT, LOG_FORMAT, LOG_DIR, ORIGIN, WSDL_URL, FRONTEND_URL, MSING_API } = process.env;

export const corsOptions = {
origin: (origin, callback) => {
if (ORIGIN.split(', ').indexOf(origin) !== -1 || !origin) {
callback(null, true);
} else {
callback(new Error('Not allowed by CORS'));
}
},
credentials: CREDENTIALS,
allowedHeaders: ['Content-Type', 'Authorization'],
methods: ['GET', 'POST'],
preflightContinue: false,
};
5 changes: 5 additions & 0 deletions src/controllers/app.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import MsignService from '@services/msign.service';

export default class AppController {
protected msignService = new MsignService();
}
1 change: 1 addition & 0 deletions src/controllers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './msign.controller';
Loading

0 comments on commit aca3702

Please sign in to comment.