Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core-explorer): initial implementation #2604

Merged
merged 3 commits into from May 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
72 changes: 54 additions & 18 deletions .circleci/config.yml

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions packages/core-explorer/.gitattributes
@@ -0,0 +1,7 @@
# Path-based git attributes
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html

# Ignore all test and documentation with "export-ignore".
/.gitattributes export-ignore
/.gitignore export-ignore
/README.md export-ignore
21 changes: 21 additions & 0 deletions packages/core-explorer/README.md
@@ -0,0 +1,21 @@
# ARK Core - Explorer

<p align="center">
<img src="https://raw.githubusercontent.com/ARKEcosystem/core/master/banner.png" />
</p>

## Documentation

You can find installation instructions and detailed instructions on how to use this package at the [dedicated documentation site](https://docs.ark.io/guidebook/core/plugins/optional/core-explorer.html).

## Security

If you discover a security vulnerability within this package, please send an e-mail to security@ark.io. All security vulnerabilities will be promptly addressed.

## Credits

This project exists thanks to all the people who [contribute](../../../../contributors).

## License

[MIT](LICENSE) © [ARK Ecosystem](https://ark.io)
37 changes: 37 additions & 0 deletions packages/core-explorer/package.json
@@ -0,0 +1,37 @@
{
"name": "@arkecosystem/core-explorer",
"version": "2.4.0-next.4",
"description": "Explorer for ARK Core",
"license": "MIT",
"contributors": [
"Brian Faust <brian@ark.io>"
],
"files": [
"dist"
],
"main": "dist/index",
"scripts": {
"build": "yarn clean && yarn compile",
"build:watch": "yarn clean && yarn compile -w",
"clean": "del dist",
"compile": "../../node_modules/typescript/bin/tsc",
"prepublishOnly": "yarn build",
"pretest": "bash ../../scripts/pre-test.sh"
},
"dependencies": {
"@arkecosystem/core-container": "^2.4.0-next.4",
"@arkecosystem/core-interfaces": "^2.4.0-next.4",
"connect-history-api-fallback": "^1.6.0",
"express": "^4.17.0"
},
"engines": {
"node": ">=10.x"
},
"publishConfig": {
"access": "public"
},
"devDependencies": {
"@types/connect-history-api-fallback": "^1.3.2",
"@types/express": "^4.16.1"
}
}
7 changes: 7 additions & 0 deletions packages/core-explorer/src/defaults.ts
@@ -0,0 +1,7 @@
export const defaults = {
server: {
host: process.env.CORE_EXPLORER_HOST || "0.0.0.0",
port: process.env.CORE_EXPLORER_PORT || 4200,
},
path: process.env.CORE_EXPLORER_PATH,
};
49 changes: 49 additions & 0 deletions packages/core-explorer/src/index.ts
@@ -0,0 +1,49 @@
import { Container, Logger } from "@arkecosystem/core-interfaces";
import history from "connect-history-api-fallback";
import express, { Handler } from "express";
import { existsSync } from "fs";
import { defaults } from "./defaults";

export const plugin: Container.IPluginDescriptor = {
pkg: require("../package.json"),
defaults,
alias: "explorer",
async register(container: Container.IContainer, options) {
const distPath: string = options.path as string;

if (!existsSync(distPath)) {
container
.resolvePlugin<Logger.ILogger>("logger")
.error(`The ${distPath} directory does not exist. Please build the explorer before using this plugin.`);

return undefined;
}

const staticFileMiddleware: Handler = express.static(distPath);

const app: express.Application = express();
app.use(staticFileMiddleware);
app.use(history());
app.use(staticFileMiddleware);
app.get("/", (req, res) => res.render(`${distPath}/index.html`));

// @ts-ignore
const server = app.listen(options.server.port, options.server.host, () => {
container
.resolvePlugin<Logger.ILogger>("logger")
// @ts-ignore
.info(`Explorer is listening on http://${server.address().address}:${server.address().port}.`);
});

return server;
},
async deregister(container: Container.IContainer, options) {
try {
container.resolvePlugin<Logger.ILogger>("logger").info("Stopping Explorer");

await container.resolvePlugin("explorer").close();
} catch (error) {
// do nothing...
}
},
};
7 changes: 7 additions & 0 deletions packages/core-explorer/tsconfig.json
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist"
},
"include": ["src/**/**.ts"]
}