mirror of
https://github.com/oceanprotocol/commons.git
synced 2023-03-15 18:03:00 +01:00
testing tweaks
This commit is contained in:
parent
c49fc85017
commit
2a0401be7f
@ -27,7 +27,7 @@ npm start
|
||||
```
|
||||
|
||||
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
|
||||
Open [http://localhost:3000](http://localhost:3000) to view the client in the browser.
|
||||
|
||||
The page will reload if you make edits to files in either `./client` or `./server`.
|
||||
|
||||
|
@ -8,9 +8,9 @@
|
||||
"build": "./scripts/build.sh",
|
||||
"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:css": "prettier-stylelint --ignore-path .gitignore --write --quiet '**/*.{css,scss}'",
|
||||
"format": "npm run format:js && npm run format:css",
|
||||
"lint:css": "stylelint './**/*.{css,scss}'",
|
||||
"lint:css": "stylelint --ignore-path .gitignore './**/*.{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"
|
||||
|
0
scripts/test.sh
Normal file → Executable file
0
scripts/test.sh
Normal file → Executable file
@ -1,5 +1,7 @@
|
||||
module.exports = {
|
||||
const config = {
|
||||
app: {
|
||||
port: 4000
|
||||
}
|
||||
}
|
||||
|
||||
export default config
|
||||
|
@ -8,12 +8,31 @@ import bodyParser from 'body-parser'
|
||||
import UrlCheckRouter from './routes/UrlCheckRouter'
|
||||
|
||||
// config
|
||||
const config = require('./config/config')
|
||||
import config from './config/config'
|
||||
|
||||
// debug
|
||||
const log = debug('server:index')
|
||||
|
||||
const app = express()
|
||||
|
||||
function onListening(): void {
|
||||
log('Server thread started')
|
||||
}
|
||||
|
||||
function onError(error: NodeJS.ErrnoException): void {
|
||||
if (error.syscall !== 'listen') throw error
|
||||
switch (error.code) {
|
||||
case 'EACCES':
|
||||
log('Required elevated privileges')
|
||||
process.exit(1)
|
||||
case 'EADDRINUSE':
|
||||
log('Port is already in use')
|
||||
process.exit(1)
|
||||
default:
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
app.use((req, res, next) => {
|
||||
res.header('Access-Control-Allow-Origin', '*')
|
||||
res.header(
|
||||
@ -32,33 +51,15 @@ app.use(bodyParser.urlencoded({ extended: false }))
|
||||
app.use(compression())
|
||||
// routes
|
||||
app.use('/api/v1/urlcheck', UrlCheckRouter)
|
||||
|
||||
/// catch 404
|
||||
app.use((req, res, next) => {
|
||||
res.status(404).send()
|
||||
})
|
||||
|
||||
// listen
|
||||
const server = app.listen(config.app.port)
|
||||
server.on('listening', onListening)
|
||||
server.on('error', onError)
|
||||
|
||||
function onListening(): void {
|
||||
log('Server thread started')
|
||||
}
|
||||
|
||||
function onError(error: NodeJS.ErrnoException): void {
|
||||
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
|
||||
default:
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
export default server
|
||||
|
@ -2,12 +2,12 @@ import { Router, Request, Response, NextFunction } from 'express'
|
||||
import request from 'request'
|
||||
|
||||
export class UrlCheckRouter {
|
||||
router: Router
|
||||
public router: Router
|
||||
|
||||
/**
|
||||
* Initialize the UrlCheckRouter
|
||||
*/
|
||||
constructor() {
|
||||
public constructor() {
|
||||
this.router = Router()
|
||||
}
|
||||
|
||||
@ -25,22 +25,28 @@ export class UrlCheckRouter {
|
||||
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]
|
||||
|
||||
result.contentType = typeAndCharset[0] // eslint-disable-line prefer-destructuring
|
||||
|
||||
if (typeAndCharset[1]) {
|
||||
/* eslint-disable prefer-destructuring */
|
||||
result.contentCharset = typeAndCharset[1].split(
|
||||
'='
|
||||
)[1]
|
||||
/* eslint-enable prefer-destructuring */
|
||||
}
|
||||
}
|
||||
return res.send({ status: 'success', result: result })
|
||||
return res.send({ status: 'success', result })
|
||||
}
|
||||
return res.send({ status: 'error', message: error })
|
||||
}
|
||||
@ -51,7 +57,7 @@ export class UrlCheckRouter {
|
||||
* Take each handler, and attach to one of the Express.Router's
|
||||
* endpoints.
|
||||
*/
|
||||
init() {
|
||||
public init() {
|
||||
this.router.post('/', this.checkUrl)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user