Coder Social home page Coder Social logo

michaelsanford / timeout-as-a-service Goto Github PK

View Code? Open in Web Editor NEW
5.0 3.0 4.0 254 KB

A ridiculous API that will respond with a given status after a given timeout, written in Nodejs.

Home Page: https://michaelsanford.com/timeout-as-a-service/

License: MIT License

JavaScript 100.00%
api timeout nodejs restify npm ajax xmlhttprequest

timeout-as-a-service's Introduction

Timeout as a Service

Node.js CI CodeQL

I "needed" this for a Pen playing with offline detection. It is, of course, a silly idea. Parafoxically it has found one or two quasi-legitimate uses.

It's now archived.

Deploying on Heroku

For fast and simple deployment on Heroku, you can use the button below.

Deploy to Heroku

API

Sports a handeh-dandeh two-parameter API.

Specification

Call the API with your choice of GET, PUT, POST, DELETE with

  • a timeout in miliseconds, and
  • a valid status code you want returned
https://timeout-as-a-service.herokuapp.com/<timeout-in_miliseconds>/<status_code>

You'll get back a JSON object once the request completes:

{
    "waitTime": 1000,
    "status": 200
}

Public API on Heroku:

https://timeout-as-a-service.herokuapp.com/5000/418

CORS Support

CORS allows Origin '*', so you should be able to use this from anywhere.

Security

  • No, it won't reflect a response elsewhere. Obviously. That would be insane.
  • By default wait times are limited to 90 seconds unless you have specified a different maximum wait time with the MAX_WAIT_TIME environment variable.

Example XMLHttpRequest

const timeout = 2000,
const status = 200;
const url = `https://timeout-as-a-service.herokuapp.com/${timeout}/${status}`;

request = new XMLHttpRequest();

request.addEventListener("timeout", () => console.log("Timed out!"));
request.addEventListener("load", data => console.dir(data));

// This will cause a timeout:
request.timeout = timeout - 1000;

request.open("GET", url);
request.send();

Contributing

If you want a feature or have a question:

If unsatisfied by what you find, please file an issue.

If you already have a solution in mind, you can then fork, and submit a pull request, but please file an issue first.

License

MIT

timeout-as-a-service's People

Contributors

aulisius avatar codacy-badger avatar dependabot[bot] avatar ericadamski avatar frewacom avatar michaelsanford avatar terencehuynh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

timeout-as-a-service's Issues

Make CORS environment-configurable

Probably something like this...

Configuration at the top:

const CORS_ORIGINS = process.env.CORS_ORIGINS || "*";
const CORS_METHODS = process.env.CORS_METHODS || "GET, PUT, POST, DELETE, HEAD";

Then implementation:

server.use(
    restify.CORS({
        origins: CORS_ORIGINS,
        headers: CORS_METHODS
      })
);

And add

env:
- CORS_ORIGINS ="* s.codepen.io"
- CORS_METHODS = "GET, PUT, POST, DELETE, HEAD"

to .travis.yml

Relates #4

Create a 'Deploy to Heroku' Button

Create a 'Deploy to Heroku' Button for this project.

https://devcenter.heroku.com/articles/heroku-button

Most of the "value" in this somewhat toy project is the ability to use it quasi-internally for your own projects. Since I already deploy it to Heroku, might as well try this!

It's open for anyone to contribute to, but it would be really handy if you actually have a Heroku account to test it with 😉

[DepShield] (CVSS 7.4) Vulnerability due to usage of lodash.get:4.4.2

Vulnerabilities

DepShield reports that this application's usage of lodash.get:4.4.2 results in the following vulnerability(s):


Occurrences

lodash.get:4.4.2 is a transitive dependency introduced by the following direct dependency(s):

restify:7.7.0
        └─ csv:1.2.1
              └─ csv-stringify:1.1.2
                    └─ lodash.get:4.4.2

sinon:7.2.3
        └─ @sinonjs/samsam:3.1.0
              └─ lodash.get:4.4.2

This is an automated GitHub Issue created by Sonatype DepShield. Details on managing GitHub Apps, including DepShield, are available for personal and organization accounts. Please submit questions or feedback about DepShield to the Sonatype DepShield Community.

Fix build because of Restify

The build id broken.

Updating nvm
nvm.install
2.62s$ nvm install 8
Downloading and installing node v8.12.0...
Downloading https://nodejs.org/dist/v8.12.0/node-v8.12.0-linux-x64.tar.xz...
Computing checksum with sha256sum
Checksums matched!
Now using node v8.12.0 (npm v6.4.1)
$ node --version
v8.12.0
$ npm --version
6.4.1
$ nvm --version
0.33.11
5.28s$ npm ci 
npm ERR! Invalid Version: https://registry.npmjs.org/restify/-/restify-4.3.0.tgz
npm ERR! A complete log of this run can be found in:
npm ERR!     /home/travis/.npm/_logs/2018-09-11T21_06_42_354Z-debug.log

Landing page

Exploding with an error when GET / is not great.

Return instructions, printed as JSON (because I want to reinforce that there is no UI).

Add tests

If someone submitted a pull request that broke this internet-critical service and we had no tests to block it, the world might stop rotating on its axis. We can't have that... 🙅‍♂️

In all likelihood, the culprit will be me...

Tests

  1. {GET, PUT, POST, DELETE} requests, with
  2. {3000, 10000} millisecond wait times, and
  3. {200, 418} return codes
  4. Test the malformed request /
  5. Test the malformed request /abc/123

/docs

Write some docs for a GitHub Pages site.

Add Travis

Add travis

Travis

  1. Add a .travis.yml to the project
  2. Add this guy to the README: Build Status

Add npm start

Because npm init asks for your insertion script and tests, but only scaffolds npm test for some reason...

[DepShield] (CVSS 7.5) Vulnerability due to usage of debug:2.6.9

Vulnerabilities

DepShield reports that this application's usage of debug:2.6.9 results in the following vulnerability(s):


Occurrences

debug:2.6.9 is a transitive dependency introduced by the following direct dependency(s):

restify:7.7.0
        └─ spdy:3.4.7
              └─ debug:2.6.9
              └─ spdy-transport:2.1.1
                    └─ debug:2.6.9

This is an automated GitHub Issue created by Sonatype DepShield. Details on managing GitHub Apps, including DepShield, are available for personal and organization accounts. Please submit questions or feedback about DepShield to the Sonatype DepShield Community.

Internal Server Error

MAX_WAIT_TIME is undefined in index.js

The definition is only made in wait.js.

res.status().json is not a function.

res.json is sufficient

Fix CORS

XMLHttpRequest cannot load https://timeout-as-a-service.herokuapp.com/2000/200.
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'https://s.codepen.io' is therefore not allowed access.

bitmoji

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.