1
0
mirror of https://github.com/oceanprotocol/commons.git synced 2023-03-15 18:03:00 +01:00

one dev interface for client & server

This commit is contained in:
Matthias Kretschmann 2019-03-23 22:10:00 -03:00
parent 366f48b9ad
commit 7e42991706
Signed by: m
GPG Key ID: 606EEEF3C479A91F
28 changed files with 6707 additions and 2812 deletions

View File

@ -1,15 +1,14 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
node_modules
# testing
/coverage
coverage
# production
/build
build
dist
# misc
.DS_Store

View File

@ -1,2 +1,3 @@
node_modules
build
dist

View File

@ -1,8 +1,10 @@
language: node_js
node_js:
- "11.10.1"
- '11.10.1'
script: "./.travis.sh"
script:
- ./scripts/install.sh
- ./scripts/test.sh
notifications:
email: false

View File

@ -2,40 +2,44 @@
<h1 align="center">commons-marketplace</h1>
> Marketplace front-end to explore, download, and publish open data sets.
> Marketplace front-end and backend server to explore, download, and publish open data sets.
[![Build Status](https://travis-ci.com/oceanprotocol/commons-marketplace.svg?token=3psqw6c8KMDqfdGQ2x6d&branch=master)](https://travis-ci.com/oceanprotocol/commons-marketplace)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-7b1173.svg?style=flat-square)](https://github.com/prettier/prettier)
[![js oceanprotocol](https://img.shields.io/badge/js-oceanprotocol-7b1173.svg)](https://github.com/oceanprotocol/eslint-config-oceanprotocol)
[![css bigchaindb](https://img.shields.io/badge/css-bigchaindb-39BA91.svg)](https://github.com/bigchaindb/stylelint-config-bigchaindb)
- [Development](#development)
- [Get Started](#get-started)
- [Production](#production)
- [Testing](#testing)
- [Code Style](#code-style)
- [License](#license)
<img alt="screen shot 2019-02-08 at 16 53 57" src="https://user-images.githubusercontent.com/90316/52489283-27080e80-2bc2-11e9-8ec0-508c21eb86f7.png">
## Development
## Get Started
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
To spin up both, the client and the server in a watch mode for local development, execute:
```bash
npm install
npm start
```
Runs the app in the development mode.<br>
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
This will run client and server in development mode.<br>
Open [http://localhost:3000](http://localhost:3000) to view the client in the browser. The server is
The page will reload if you make edits.<br>
You will also see any lint errors in the console.
The page will reload if you make edits to files in either `./client` or `./server`.
## Production
To create a production build of both, the client and the server:
```bash
npm run build
```
Builds the app for production to the `build` folder.<br>
It correctly bundles React in production mode and optimizes the build for the best performance.
Builds the client for production to the `./client/build` folder, and the server into the `./server/dist` folder.
## Testing

View File

@ -1,13 +0,0 @@
language: node_js
node_js: node
script:
- npm test
- npm run build
notifications:
email: false
cache:
directories:
- node_modules

2387
client/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,19 +1,12 @@
{
"name": "commons-marketplace",
"name": "commons-marketplace-client",
"version": "0.1.0",
"private": true,
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "npm run lint && react-scripts test",
"eject": "react-scripts eject",
"format:js": "prettier --parser typescript --write '**/*.{js,jsx,ts,tsx}'",
"format:css": "prettier-stylelint --write --quiet 'src/**/*.{css,scss}'",
"format": "npm run format:js && npm run format:css",
"lint:css": "stylelint './src/**/*.{css,scss}'",
"lint:js": "eslint --ignore-path .gitignore --ignore-path .prettierignore --ext .ts,.tsx .",
"lint:fix": "eslint --fix --ignore-path .gitignore --ignore-path .prettierignore --ext .ts,.tsx .",
"lint": "npm run lint:js && npm run lint:css"
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"dependencies": {
"@oceanprotocol/art": "^2.2.0",
@ -47,21 +40,8 @@
"@types/react-router-dom": "^4.3.1",
"@types/react-transition-group": "^2.0.16",
"@types/web3": "^1.0.18",
"@typescript-eslint/eslint-plugin": "^1.4.2",
"@typescript-eslint/parser": "^1.4.2",
"eslint": "5.12.0",
"eslint-config-oceanprotocol": "^1.3.0",
"eslint-config-prettier": "^4.1.0",
"eslint-plugin-prettier": "^3.0.1",
"node-sass": "^4.11.0",
"prettier": "^1.16.4",
"prettier-stylelint": "^0.4.2",
"react-scripts": "^2.1.5",
"stylelint": "^9.10.1",
"stylelint-config-bigchaindb": "^1.2.1",
"stylelint-config-css-modules": "^1.3.0",
"stylelint-config-standard": "^18.2.0",
"typescript": "^3.3.3333"
"react-scripts": "^2.1.5"
},
"browserslist": [
">0.2%",

6475
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

40
package.json Normal file
View File

@ -0,0 +1,40 @@
{
"name": "commons-marketplace",
"version": "0.1.0",
"private": true,
"scripts": {
"install": "./scripts/install.sh",
"start": "cd client && npm run start",
"build": "cd client && npm run build",
"test": "npm run lint && scripts/test.sh",
"format:js": "prettier --parser typescript --write '**/*.{js,jsx,ts,tsx}'",
"format:css": "prettier-stylelint --write --quiet '**/*.{css,scss}'",
"format": "npm run format:js && npm run format:css",
"lint:css": "stylelint './**/*.{css,scss}'",
"lint:js": "eslint --ignore-path .gitignore --ignore-path .prettierignore --ext .ts,.tsx .",
"lint:fix": "eslint --fix --ignore-path .gitignore --ignore-path .prettierignore --ext .ts,.tsx .",
"lint": "npm run lint:js && npm run lint:css"
},
"dependencies": {},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^1.4.2",
"@typescript-eslint/parser": "^1.4.2",
"eslint": "5.12.0",
"eslint-config-oceanprotocol": "^1.3.0",
"eslint-config-prettier": "^4.1.0",
"eslint-plugin-prettier": "^3.0.1",
"prettier": "^1.16.4",
"prettier-stylelint": "^0.4.2",
"stylelint": "^9.10.1",
"stylelint-config-bigchaindb": "^1.2.1",
"stylelint-config-css-modules": "^1.3.0",
"stylelint-config-standard": "^18.2.0",
"typescript": "^3.3.3333"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}

12
scripts/install.sh Executable file
View File

@ -0,0 +1,12 @@
#/usr/bin/env/sh
set -e
components="server client"
for component in $components
do
echo "Installing dependencies: $component"
cd $component
npm install
cd ..
done

2
.travis.sh → scripts/test.sh Executable file → Normal file
View File

@ -1,12 +1,12 @@
#/usr/bin/env/sh
set -e
components="server client"
for component in $components
do
echo "Testing: $component"
cd $component
npm install
npm test
cd ..
done

38
server/.gitignore vendored
View File

@ -1,38 +0,0 @@
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz
*.swp
pids
logs
results
tmp
# Build
dist
# Coverage reports
coverage
# API keys and secrets
.env
# Dependency directory
node_modules
bower_components
# Editors
.idea
*.iml
# OS metadata
.DS_Store
Thumbs.db
# Ignore built ts files
dist/**/*

129
server/package-lock.json generated
View File

@ -1,5 +1,5 @@
{
"name": "backend",
"name": "commons-marketplace-server",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
@ -574,65 +574,6 @@
"resolved": "https://registry.npmjs.org/aws4/-/aws4-1.8.0.tgz",
"integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ=="
},
"babel-code-frame": {
"version": "6.26.0",
"resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz",
"integrity": "sha1-Y/1D99weO7fONZR9uP42mj9Yx0s=",
"dev": true,
"requires": {
"chalk": "^1.1.3",
"esutils": "^2.0.2",
"js-tokens": "^3.0.2"
},
"dependencies": {
"ansi-regex": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz",
"integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=",
"dev": true
},
"ansi-styles": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz",
"integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=",
"dev": true
},
"chalk": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
"integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=",
"dev": true,
"requires": {
"ansi-styles": "^2.2.1",
"escape-string-regexp": "^1.0.2",
"has-ansi": "^2.0.0",
"strip-ansi": "^3.0.0",
"supports-color": "^2.0.0"
}
},
"js-tokens": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz",
"integrity": "sha1-mGbfOVECEw449/mWvOtlRDIJwls=",
"dev": true
},
"strip-ansi": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
"integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=",
"dev": true,
"requires": {
"ansi-regex": "^2.0.0"
}
},
"supports-color": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz",
"integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=",
"dev": true
}
}
},
"babel-jest": {
"version": "24.1.0",
"resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-24.1.0.tgz",
@ -899,12 +840,6 @@
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz",
"integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A=="
},
"builtin-modules": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-1.1.1.tgz",
"integrity": "sha1-Jw8HbFpywC9bZaR9+Uxf46J4iS8=",
"dev": true
},
"busboy": {
"version": "0.2.14",
"resolved": "https://registry.npmjs.org/busboy/-/busboy-0.2.14.tgz",
@ -1144,7 +1079,8 @@
"version": "2.17.1",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.17.1.tgz",
"integrity": "sha512-wPMUt6FnH2yzG95SA6mzjQOEKUU3aLaDEmzs1ti+1E9h+CsrZghRlqEM/EJ4KscsQVG8uNN4uVreUeT8+drlgg==",
"dev": true
"dev": true,
"optional": true
},
"compare-versions": {
"version": "3.4.0",
@ -2866,23 +2802,6 @@
"function-bind": "^1.1.1"
}
},
"has-ansi": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz",
"integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE=",
"dev": true,
"requires": {
"ansi-regex": "^2.0.0"
},
"dependencies": {
"ansi-regex": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz",
"integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=",
"dev": true
}
}
},
"has-flag": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
@ -6110,47 +6029,11 @@
"yn": "^3.0.0"
}
},
"tslib": {
"version": "1.9.3",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz",
"integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==",
"dev": true
},
"tslint": {
"version": "5.13.1",
"resolved": "https://registry.npmjs.org/tslint/-/tslint-5.13.1.tgz",
"integrity": "sha512-fplQqb2miLbcPhyHoMV4FU9PtNRbgmm/zI5d3SZwwmJQM6V0eodju+hplpyfhLWpmwrDNfNYU57uYRb8s0zZoQ==",
"dev": true,
"requires": {
"babel-code-frame": "^6.22.0",
"builtin-modules": "^1.1.1",
"chalk": "^2.3.0",
"commander": "^2.12.1",
"diff": "^3.2.0",
"glob": "^7.1.1",
"js-yaml": "^3.7.0",
"minimatch": "^3.0.4",
"mkdirp": "^0.5.1",
"resolve": "^1.3.2",
"semver": "^5.3.0",
"tslib": "^1.8.0",
"tsutils": "^2.27.2"
}
},
"tsscmp": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/tsscmp/-/tsscmp-1.0.6.tgz",
"integrity": "sha512-LxhtAkPDTkVCMQjt2h6eBVY28KCjikZqZfMcC15YBeNjkgUpdCfBu5HoiOTDu86v6smE8yOjyEktJ8hlbANHQA=="
},
"tsutils": {
"version": "2.29.0",
"resolved": "https://registry.npmjs.org/tsutils/-/tsutils-2.29.0.tgz",
"integrity": "sha512-g5JVHCIJwzfISaXpXE1qvNalca5Jwob6FjI4AoPlqMusJ6ftFE7IkkFoMhVLRgK+4Kx3gkzb8UZK5t5yTTvEmA==",
"dev": true,
"requires": {
"tslib": "^1.8.1"
}
},
"tunnel-agent": {
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz",
@ -6193,12 +6076,6 @@
"resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz",
"integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c="
},
"typescript": {
"version": "3.3.3333",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.3.3333.tgz",
"integrity": "sha512-JjSKsAfuHBE/fB2oZ8NxtRTk5iGcg6hkYXMnZ3Wc+b2RSqejEqTaem11mHASMnFilHrax3sLK0GDzcJrekZYLw==",
"dev": true
},
"uglify-js": {
"version": "3.4.9",
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.4.9.tgz",

View File

@ -1,19 +1,15 @@
{
"name": "backend",
"name": "commons-marketplace-server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"main": "dist/index.js",
"scripts": {
"start": "npm run serve",
"start": "node dist/index.js",
"start-watch": "nodemon",
"build": "npm run build-ts && npm run tslint",
"watch": "npm run watch-ts",
"serve": "node dist/index.js",
"build": "tsc",
"watch": "tsc -w",
"test": "jest --coverage",
"watch-test": "npm run test --watchAll",
"build-ts": "tsc",
"watch-ts": "tsc -w",
"tslint": "tslint -c tslint.json -p tsconfig.json"
"watch-test": "npm run test --watchAll"
},
"author": "",
"license": "ISC",
@ -47,9 +43,7 @@
"nodemon": "^1.18.10",
"supertest": "^3.4.2",
"ts-jest": "^24.0.0",
"ts-node": "^8.0.2",
"tslint": "^5.12.1",
"typescript": "^3.3.3"
"ts-node": "^8.0.2"
},
"jest": {
"preset": "ts-jest"

View File

@ -2,4 +2,4 @@ module.exports = {
app: {
port: 4000
}
};
}

View File

@ -1,58 +1,64 @@
import debug from "debug";
import express from "express";
import compression from "compression";
import morgan from "morgan";
import bodyParser from "body-parser";
import debug from 'debug'
import express from 'express'
import compression from 'compression'
import morgan from 'morgan'
import bodyParser from 'body-parser'
// routes
import UrlCheckRouter from "./routes/UrlCheckRouter";
import UrlCheckRouter from './routes/UrlCheckRouter'
// config
const config = require("./config/config");
const config = require('./config/config')
// debug
const log = debug("server:index");
const log = debug('server:index')
const app = express();
const app = express()
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
res.header("Access-Control-Allow-Methods", "GET, POST, OPTIONS, PUT, DELETE");
next();
});
app.use(morgan("dev"));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(compression());
res.header('Access-Control-Allow-Origin', '*')
res.header(
'Access-Control-Allow-Headers',
'Origin, X-Requested-With, Content-Type, Accept, Authorization'
)
res.header(
'Access-Control-Allow-Methods',
'GET, POST, OPTIONS, PUT, DELETE'
)
next()
})
app.use(morgan('dev'))
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }))
app.use(compression())
// routes
app.use("/api/v1/urlcheck", UrlCheckRouter);
app.use('/api/v1/urlcheck', UrlCheckRouter)
/// catch 404
app.use((req, res, next) => {
res.status(404).send();
});
res.status(404).send()
})
// listen
const server = app.listen(config.app.port);
server.on("listening", onListening);
server.on("error", onError);
const server = app.listen(config.app.port)
server.on('listening', onListening)
server.on('error', onError)
function onListening(): void {
log("Server thread started");
log('Server thread started')
}
function onError(error: NodeJS.ErrnoException): void {
if (error.syscall !== "listen") throw error;
if (error.syscall !== 'listen') throw error
switch (error.code) {
case "EACCES":
log("Required elevated privileges");
process.exit(1);
break;
case "EADDRINUSE":
log("Port is already in use");
process.exit(1);
break;
case 'EACCES':
log('Required elevated privileges')
process.exit(1)
break
case 'EADDRINUSE':
log('Port is already in use')
process.exit(1)
break
default:
throw error;
throw error
}
}
export default server;
export default server

View File

@ -1,45 +1,50 @@
import { Router, Request, Response, NextFunction } from "express";
import request from "request";
import { Router, Request, Response, NextFunction } from 'express'
import request from 'request'
export class UrlCheckRouter {
router: Router;
router: Router
/**
* Initialize the UrlCheckRouter
*/
constructor() {
this.router = Router();
this.router = Router()
}
public checkUrl(req: Request, res: Response, next: NextFunction) {
if (!req.body.url) {
return res.send({ status: "error", message: "missing url" });
return res.send({ status: 'error', message: 'missing url' })
}
request(
{
method: "HEAD",
method: 'HEAD',
url: req.body.url,
headers: { Range: "bytes=0-" }
headers: { Range: 'bytes=0-' }
},
(error, response) => {
if (response.statusCode.toString().startsWith("2")) {
const result: any = {};
result.found = true;
if (response.headers["content-length"]) {
result.contentLength = response.headers["content-length"];
if (response.statusCode.toString().startsWith('2')) {
const result: any = {}
result.found = true
if (response.headers['content-length']) {
result.contentLength =
response.headers['content-length']
}
if (response.headers["content-type"]) {
const typeAndCharset = response.headers["content-type"].split(";");
result.contentType = typeAndCharset[0];
if (response.headers['content-type']) {
const typeAndCharset = response.headers[
'content-type'
].split(';')
result.contentType = typeAndCharset[0]
if (typeAndCharset[1]) {
result.contentCharset = typeAndCharset[1].split("=")[1];
result.contentCharset = typeAndCharset[1].split(
'='
)[1]
}
}
return res.send({ status: "success", result: result });
return res.send({ status: 'success', result: result })
}
return res.send({ status: "error", message: error });
return res.send({ status: 'error', message: error })
}
);
)
}
/**
@ -47,12 +52,12 @@ export class UrlCheckRouter {
* endpoints.
*/
init() {
this.router.post("/", this.checkUrl);
this.router.post('/', this.checkUrl)
}
}
// Create the MeRouter, and export its configured Express.Router
const urlCheckRoutes = new UrlCheckRouter();
urlCheckRoutes.init();
const urlCheckRoutes = new UrlCheckRouter()
urlCheckRoutes.init()
export default urlCheckRoutes.router;
export default urlCheckRoutes.router

View File

@ -1,15 +1,15 @@
import request from "supertest";
import server from "../src";
import {} from "jasmine";
import request from 'supertest'
import server from '../src'
import {} from 'jasmine'
afterAll((done) => {
server.close(done);
});
afterAll(done => {
server.close(done)
})
describe("POST /api/v1/urlcheck", () => {
describe('POST /api/v1/urlcheck', () => {
it('responds with json', function(done) {
request(server)
.post('/api/v1/urlcheck')
.expect(200, done);
});
});
.expect(200, done)
})
})

View File

@ -9,17 +9,10 @@
"outDir": "dist",
"baseUrl": ".",
"paths": {
"*": [
"node_modules/*",
"src/types/*"
]
"*": ["node_modules/*", "src/types/*"]
},
"types": ["node"],
"typeRoots": [
"node_modules/@types"
],
"typeRoots": ["node_modules/@types"]
},
"include": [
"src/**/*"
]
"include": ["src/**/*"]
}

View File

@ -1,60 +0,0 @@
{
"rules": {
"class-name": true,
"comment-format": [
true,
"check-space"
],
"indent": [
true,
"spaces"
],
"one-line": [
true,
"check-open-brace",
"check-whitespace"
],
"no-var-keyword": true,
"quotemark": [
true,
"double",
"avoid-escape"
],
"semicolon": [
true,
"always",
"ignore-bound-class-methods"
],
"whitespace": [
true,
"check-branch",
"check-decl",
"check-operator",
"check-module",
"check-separator",
"check-type"
],
"typedef-whitespace": [
true,
{
"call-signature": "nospace",
"index-signature": "nospace",
"parameter": "nospace",
"property-declaration": "nospace",
"variable-declaration": "nospace"
},
{
"call-signature": "onespace",
"index-signature": "onespace",
"parameter": "onespace",
"property-declaration": "onespace",
"variable-declaration": "onespace"
}
],
"no-internal-module": true,
"no-trailing-whitespace": true,
"no-null-keyword": true,
"prefer-const": true,
"jsdoc-format": true
}
}

3
tsconfig.json Normal file
View File

@ -0,0 +1,3 @@
{
"include": ["client/src", "server/src"]
}