Skip to content

CI rehab #47

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,34 @@ jobs:
steps:
- uses: actions/checkout@v2

- uses: purescript-contrib/setup-purescript@main
- name: Set up a PureScript toolchain
uses: purescript-contrib/setup-purescript@main
with:
purescript: "unstable"
purs-tidy: "0.9.0"

- uses: actions/setup-node@v2
- name: Cache PureScript dependencies
uses: actions/cache@v2
with:
node-version: "14"

key: ${{ runner.os }}-spago-${{ hashFiles('**/*.dhall') }}
path: |
.spago
output
- name: Install dependencies
run: |
npm install -g bower
npm install
bower install --production
run: spago install

- name: Build source
run: npm run-script build
run: spago build --no-install --purs-args '--censor-lib --strict'

- name: Install test dependencies
run: spago -x spago.dev.dhall install

- name: Build tests
run: spago -x spago.dev.dhall build --no-install --purs-args '--censor-lib --strict'

- name: Run tests
run: |
bower install
npm run-script test --if-present
run: spago -x spago.dev.dhall test --no-install

- name: Check formatting
run: purs-tidy check src test

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
/node_modules/
/output/
package-lock.json
generated-docs/
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ Breaking changes:

New features:

- Use __spec__ for tests. Upgraded `ci.yml`. Solves #35. (#47 by @jamesdbrock)
- New function `HTTP.onRequest`. Solves #46. (#47 by @jamesdbrock)

Bugfixes:

Other improvements:
Expand All @@ -32,7 +35,7 @@ New features:
Other improvements:
- Migrated CI to GitHub Actions, updated installation instructions to use Spago, and migrated from `jshint` to `eslint` (#30)
- Added a changelog and pull request template (#34)

## [v5.0.2](https://github.com/purescript-node/purescript-node-http/releases/tag/v5.0.2) - 2019-07-24

- Relaxed upper bounds on `node-buffer`
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@
[![Build status](https://github.com/purescript-node/purescript-node-http/workflows/CI/badge.svg?branch=master)](https://github.com/purescript-node/purescript-node-http/actions?query=workflow%3ACI+branch%3Amaster)
[![Pursuit](https://pursuit.purescript.org/packages/purescript-node-http/badge)](https://pursuit.purescript.org/packages/purescript-node-http)

A wrapper for Node's HTTP APIs.
A wrapper for Node’s [HTTP](https://nodejs.org/docs/latest/api/http.html) API.

## Installation

```
spago install node-http
```


## Test

```
spago -x spago.dev.dhall test
```

## Documentation

Module documentation is [published on Pursuit](http://pursuit.purescript.org/packages/purescript-node-http).

61 changes: 30 additions & 31 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
{
"name": "purescript-node-http",
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"output"
],
"repository": {
"type": "git",
"url": "https://github.com/purescript-node/purescript-node-http.git"
},
"devDependencies": {
"purescript-console": "^6.0.0"
},
"dependencies": {
"purescript-arraybuffer-types": "^3.0.2",
"purescript-contravariant": "^6.0.0",
"purescript-effect": "^4.0.0",
"purescript-foreign": "^7.0.0",
"purescript-foreign-object": "^4.0.0",
"purescript-maybe": "^6.0.0",
"purescript-node-buffer": "^8.0.0",
"purescript-node-net": "^4.0.0",
"purescript-node-streams": "^7.0.0",
"purescript-node-url": "^6.0.0",
"purescript-nullable": "^6.0.0",
"purescript-options": "^7.0.0",
"purescript-prelude": "^6.0.0",
"purescript-unsafe-coerce": "^6.0.0"
}
"name": "purescript-node-http",
"license": [
"MIT"
],
"repository": {
"type": "git",
"url": "https://github.com/purescript-node/purescript-node-http"
},
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"output"
],
"dependencies": {
"purescript-arraybuffer-types": "^v3.0.2",
"purescript-contravariant": "^v6.0.0",
"purescript-effect": "^v4.0.0",
"purescript-foreign": "^v7.0.0",
"purescript-foreign-object": "^v4.1.0",
"purescript-maybe": "^v6.0.0",
"purescript-node-buffer": "^v8.0.0",
"purescript-node-net": "^v4.0.0",
"purescript-node-streams": "^v7.0.0",
"purescript-node-url": "^v6.0.0",
"purescript-nullable": "^v6.0.0",
"purescript-options": "^v7.0.0",
"purescript-prelude": "^v6.0.1",
"purescript-unsafe-coerce": "^v6.0.0"
}
}
5 changes: 5 additions & 0 deletions packages.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
let upstream =
https://github.com/purescript/package-sets/releases/download/psc-0.15.4-20221102/packages.dhall
sha256:8628e413718876ce26983db1d0ce9d9e1588129117fa3bb8ed9f618db6914127

in upstream
19 changes: 19 additions & 0 deletions spago.dev.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- Spago configuration for testing.

let conf = ./spago.dhall

in conf //
{ sources = [ "src/**/*.purs", "test/**/*.purs" ]
, dependencies = conf.dependencies #
[ "aff"
, "console"
, "either"
, "exceptions"
, "foldable-traversable"
, "node-process"
, "parallel"
, "partial"
, "spec"
, "tuples"
]
}
22 changes: 22 additions & 0 deletions spago.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{ name = "node-http"
, dependencies =
[ "arraybuffer-types"
, "contravariant"
, "effect"
, "foreign"
, "foreign-object"
, "maybe"
, "node-buffer"
, "node-net"
, "node-streams"
, "node-url"
, "nullable"
, "options"
, "prelude"
, "unsafe-coerce"
]
, packages = ./packages.dhall
, sources = [ "src/**/*.purs" ]
, license = "MIT"
, repository = "https://github.com/purescript-node/purescript-node-http"
}
10 changes: 10 additions & 0 deletions src/Node/HTTP.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ export function onUpgrade(server) {
};
}

export function onRequest(server) {
return function (cb) {
return function () {
server.on("request", function (req, res) {
return cb(req)(res)();
});
};
};
}

export function setHeader(res) {
return function (key) {
return function (value) {
Expand Down
4 changes: 4 additions & 0 deletions src/Node/HTTP.purs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module Node.HTTP
, listenSocket
, onConnect
, onUpgrade
, onRequest

, httpVersion
, requestHeaders
Expand Down Expand Up @@ -77,6 +78,9 @@ foreign import onConnect :: Server -> (Request -> Socket -> Buffer -> Effect Uni
-- | Listen to `upgrade` events on the server
foreign import onUpgrade :: Server -> (Request -> Socket -> Buffer -> Effect Unit) -> Effect Unit

-- | Listen to `request` events on the server
foreign import onRequest :: Server -> (Request -> Response -> Effect Unit) -> Effect Unit

-- | Get the request HTTP version
httpVersion :: Request -> String
httpVersion = _.httpVersion <<< unsafeCoerce
Expand Down
Loading