Skip to content

Commit

Permalink
MySql Condition Bug Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-whoan authored Dec 5, 2022
1 parent 3ee4b9d commit a12de99
Show file tree
Hide file tree
Showing 14 changed files with 738 additions and 364 deletions.
38 changes: 16 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
FROM node:16.16.0
LABEL email="[email protected]"
LABEL name="Eugene Minwhoan Kim"
LABEL version="0.0.4"
LABEL description="MAPI:: The Fast & Easy REST API Server in Node JS"

RUN apt-get update && apt-get install -y \
curl \
&& rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y \
curl \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /app
WORKDIR /app

COPY . .
RUN npm install -g npm-check-updates \
ncu -u \
npm install \
npm install express \
npm install babel-cli \
npm install babel-preset \
npm install babel-preset-env \
npm install body-parser \
npm install mariadb \
npm install path \
npm install url \
npm install fs \
npm install crypto
COPY . .

RUN npm ci --only=production
RUN rm package-lock.json && rm -f node_modules
RUN npm i

COPY . /app
RUN npm ci --only=production

EXPOSE 3000
CMD [ "babel-node", "starter.js" ]
COPY . /app

EXPOSE 3000
CMD [ "node", "starter.js" ]
42 changes: 21 additions & 21 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
MIT License
Copyright (c) 2022 Eugene
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
MIT License

Copyright (c) 2022 Eugene

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
26 changes: 22 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import JwtHandler from './middleware/auth/jwtHandler.js';
//import FileTransferConfigReader from './core/fileTransferReader.js';
import API_TYPE from './core/enum/apiType.js';
import NullOrUndefinedException from './exception/nullOrUndefinedException.js';
import { objectKeysToArray } from './core/utils.js';
import { fail } from 'assert';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
Expand Down Expand Up @@ -90,7 +92,6 @@ app.all('*', function(req, res, next) {
//API 처리를 위한 HTTP Router 설정
apiConfigReader.setRouter(app);


let dba = new DBAccessor();

/* Initialize Check */
Expand Down Expand Up @@ -125,8 +126,21 @@ if(jwtObject.use === "yes"){
}

let _data = result[0];
let payloadData = {};
if(jwtObject.keys){
let _columns = objectKeysToArray(_data);

_columns.forEach( (item, index) => {
let temp = jwtObject.keys[item];
payloadData[temp] = _data[item];
});
_data = null;
} else {
payloadData = _data;
}

let jwtHandler = new JwtHandler();
jwtHandler.setPayload(_data);
jwtHandler.setPayload(payloadData);
jwtHandler.generateSignature();
let _token = jwtHandler.getJwtString();
let msg = {
Expand All @@ -144,7 +158,7 @@ if(jwtObject.use === "yes"){
return res.status(msg.code).json(msg);
});

app.post(jwtObject['verify-uri'], async (req, res) => {
app.get(jwtObject['verify-uri'], async (req, res) => {
let token = req.headers.authorization;
if(!token){
return res.status(403).json({
Expand All @@ -158,7 +172,11 @@ if(jwtObject.use === "yes"){
let verifyResult = jwtHandler.verify(jwtToken);

if(!verifyResult){
return res.status(403).send();
return res.status(403).json({
code: 403,
success: false,
message: 'Token is invalid'
});
}

return res.status(200).json({
Expand Down
26 changes: 16 additions & 10 deletions core/apiReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import ApiConfigObject from '../data/object/apiConfigObject.js';
import ApiResponser from '../middleware/http/apiResponser.js';
import ProxyWorker from '../middleware/proxy/worker.js';
import ModelConfigReader from './modelReader.js';
import { insertAt, objectKeysToArray } from './utils.js';
import NoModelFoundException from '../exception/NoModelFoundException.js';
import ConfigReader from './configReader.js';
import API_TYPE from './enum/apiType.js';
Expand Down Expand Up @@ -93,7 +92,7 @@ export default class ApiConfigReader{
if(_configInfo.data.dml.indexOf('select') !== -1){
base_app.get(
_uri,
async function(req, res, next){
async (req, res, next) => {
const _cip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;

/*
Expand Down Expand Up @@ -124,14 +123,18 @@ export default class ApiConfigReader{
code: 500,
message: HTTP_RESPONSE[500]
};
}
}

if(result.code === 200){
result.size = result.data.length;
}
// return result;
return res.status(result.code).json(result);
}
);
base_app.get(
_uri + '/*',
async function(req, res, next){
async (req, res, next) => {
const _cip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;

let apiResponser = new ApiResponser(_configInfo);
Expand All @@ -150,7 +153,10 @@ export default class ApiConfigReader{
code: 500,
message: HTTP_RESPONSE[500]
};
}
}
if(result.code === 200){
result.size = result.data.length;
}
// return result;
return res.status(result.code).json(result);
}
Expand All @@ -160,9 +166,9 @@ export default class ApiConfigReader{
if(_configInfo.data.dml.indexOf('insert') !== -1){
base_app.post(
_uri,
async function(req, res, next){
async (req, res, next) => {
const _cip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;

let apiResponser = new ApiResponser(_configInfo);
let proxyWorker = new ProxyWorker(
_configInfo.data.auth === 'yes',
Expand All @@ -189,7 +195,7 @@ export default class ApiConfigReader{
if(_configInfo.data.dml.indexOf('update') !== -1){
base_app.put(
_uri,
async function(req, res, next){
async (req, res, next) => {
const _cip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;

let apiResponser = new ApiResponser(_configInfo);
Expand All @@ -215,7 +221,7 @@ export default class ApiConfigReader{
)
base_app.put(
_uri + '/*',
async function(req, res, next){
async (req, res, next) => {
const _cip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;

let apiResponser = new ApiResponser(_configInfo);
Expand Down Expand Up @@ -244,7 +250,7 @@ export default class ApiConfigReader{
if(_configInfo.data.dml.indexOf('delete') !== -1){
base_app.delete(
_uri,
async function(req, res, next){
async (req, res, next) => {
const _cip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;

let apiResponser = new ApiResponser(_configInfo);
Expand Down
2 changes: 1 addition & 1 deletion core/configReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const properties = [
'base-uri'
],
[
'id', 'pw', 'host', 'port', 'scheme'
'type', 'id', 'pw', 'host', 'port', 'scheme'
],
[
'use',
Expand Down
6 changes: 3 additions & 3 deletions core/enum/processExitCode.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const PROCESS_EXIT_CODE = {
UNKNOWN_ERROR: -1,
DB_FAIL_TO_CONNECT: 1,
DB_ACCESS_DENIED: 2
UNKNOWN_ERROR: -99,
DB_FAIL_TO_CONNECT: -1,
DB_ACCESS_DENIED: -2
};

export default PROCESS_EXIT_CODE;
8 changes: 8 additions & 0 deletions exception/unknownDatabaseAccessorException.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class UnknownDatabaseAccessorException extends Error{
constructor(message){
super(message);
this.name = 'UnknownDatabaseAccessorException';
}
}

export default UnknownDatabaseAccessorException;
Loading

0 comments on commit a12de99

Please sign in to comment.