Skip to content

Commit

Permalink
Merge pull request #27 from onixjs/development
Browse files Browse the repository at this point in the history
Release 1.0.0-alpha.19 🚀
  • Loading branch information
jonathan-casarrubias committed Apr 22, 2018
2 parents 115b2a6 + 43dddac commit 32ab682
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 46 deletions.
24 changes: 21 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@onixjs/core",
"version": "1.0.0-alpha.18.3",
"description": "The High-Performance SOA Real-Time Framework for Node.JS",
"version": "1.0.0-alpha.19",
"description": "An Enterprise Grade NodeJS Platform that implements Industry Standards and Patterns in order to provide Connectivity, Stability, High-Availability and High-Performance.",
"main": "dist/src/index.js",
"scripts": {
"build": "npm run lint:fix && npm run build:dist && npm run build:dist6 && npm run build:docs",
Expand Down Expand Up @@ -111,5 +111,23 @@
"**/__tests__/**",
"**/node_modules/**"
]
}
},
"keywords":[
"OnixJS",
"TypeScript",
"ES6",
"ES7",
"Entrprise",
"Framework",
"Platform",
"SOA",
"MSA",
"MVC",
"RPC",
"RealTime",
"IdP",
"OIDC",
"OpenID",
"oAuth"
]
}
92 changes: 50 additions & 42 deletions src/core/app.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,26 +248,30 @@ export class AppFactory {
this.config.cwd || process.cwd(),
config.endpoint || '/',
);
const AsyncLStat = promisify(fs.lstat);
const stats: fs.Stats = await AsyncLStat(pathname);
let match: string | undefined;
if (stats.isDirectory()) {
const files: string[] = <string[]>await AsyncWalk(pathname);
match = files
.filter((file: string) =>
file.match(new RegExp('\\b' + req.url + '\\b', 'g')),
)
.pop();
try {
const AsyncLStat = promisify(fs.lstat);
const stats: fs.Stats = await AsyncLStat(pathname);
let match: string | undefined;
if (stats.isDirectory()) {
const files: string[] = <string[]>await AsyncWalk(pathname);
match = files
.filter((file: string) =>
file.match(new RegExp('\\b' + req.url + '\\b', 'g')),
)
.pop();
}
await this.view(
instance,
method,
config,
match || pathname,
req,
res,
next,
);
} catch (e) {
next();
}
await this.view(
instance,
method,
config,
match || pathname,
req,
res,
next,
);
});
break;
case RouterTypes.VIEW:
Expand Down Expand Up @@ -345,30 +349,34 @@ export class AppFactory {
// Promisify exists and readfile
const AsyncExists = promisify(fs.exists);
const AsyncReadFile = promisify(fs.readFile);
// Verify the pathname exists
const exist: boolean = await AsyncExists(pathname);
// If not, return 404 code
if (!exist) {
// if the file is not found, return 404
res.statusCode = 404;
console.log(
`ONIXJS Error: The configured pathfile "${pathname}" does not exist`,
);
return res.end(
JSON.stringify({
code: res.statusCode,
message: `Oops!!! something went wrong.`,
}),
);
}
try {
// read file from file system
const data = await AsyncReadFile(pathname);
// Potentially get cookies and headers
const result = await instance[method](req, data);
// Set response headers
res.setHeader('Content-type', map[ext] || 'text/plain');
res.end(Utils.IsJsonString(result) ? JSON.stringify(result) : result);
// Verify the pathname exists
const exist: boolean = await AsyncExists(pathname);
// If not, return 404 code
if (!exist) {
// if the file is not found, return 404
res.statusCode = 404;
console.log(
`ONIXJS Error: The configured pathfile "${pathname}" does not exist`,
);
return res.end(
JSON.stringify({
code: res.statusCode,
message: `Oops!!! something went wrong.`,
}),
);
}
try {
// read file from file system
const data = await AsyncReadFile(pathname);
// Potentially get cookies and headers
const result = await instance[method](req, data);
// Set response headers
res.setHeader('Content-type', map[ext] || 'text/plain');
res.end(Utils.IsJsonString(result) ? JSON.stringify(result) : result);
} catch (e) {
next();
}
} catch (e) {
next();
}
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class OnixJS {
* @description Current Onix Version.
*/
get version(): string {
return '1.0.0-alpha.18.3';
return '1.0.0-alpha.19';
}
/**
* @property server
Expand Down

0 comments on commit 32ab682

Please sign in to comment.