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/GitHub actions support #4

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
21 changes: 21 additions & 0 deletions .github/workflows/javascript-package-publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Javascript Package Publish
on:
push:
tags:
- "*"
jobs:
publish:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 12
registry-url: https://npm.pkg.github.com/
- run: npm install
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.ACTIONS_TOKEN}}
58 changes: 30 additions & 28 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,21 @@ function default404Handler(req, res, server) {


function default405Handler(req, res, methods, server) {
res.header('Allow', methods.join(', '));
if (req.method === 'OPTIONS') {
res.header('Access-Control-Allow-Methods', methods.join(', '));
res.send(200);
res.header('Access-Control-Allow-Methods', ['GET, POST, OPTIONS, PUT']);
res.header('Access-Control-Allow-Headers', 'Authorization,Content-Type,Accept,Origin,User-Agent,DNT,Cache-Control,X-Mx-ReqToken,Keep-Alive,X-Requested-With,If-Modified-Since,x-host');
res.header('Access-Control-Allow-Origin', req.headers['origin']);
res.header('Access-Control-Allow-Credentials', true);
res.header('Access-Control-Max-Age', 1728000);
res.header('Content-Length', 0);
res.header('Content-Type', 'text/plain charset=UTF-8', 0);
res.send(204);
} else {
var msg = req.url + ' does not support ' + req.method;
res.send(new BadMethodError(msg));
}

server.emit('after', req, res, null);
}


function defaultBadVersionHandler(req, res, versions, server) {
var msg = req.method + ' ' + req.url + ' supports versions: ' +
versions.join(', ');
Expand All @@ -85,7 +87,7 @@ function defaultBadVersionHandler(req, res, versions, server) {

function toPort(x) {
x = parseInt(x, 10);
return (x >= 0 ? x : false);
return (x >= 0 ? x : false);
}


Expand Down Expand Up @@ -147,12 +149,12 @@ function Server(options) {
}

this.server.on('error', function (err) {
self.log.trace({err: err}, 'error');
self.log.trace({ err: err }, 'error');
self.emit('error', err);
});

this.server.on('clientError', function (err) {
self.log.trace({err: err}, 'clentError');
self.log.trace({ err: err }, 'clentError');
self.emit('clientError', err);
});

Expand Down Expand Up @@ -271,23 +273,23 @@ Server.prototype.listen = function listen() {
arguments[0] = Number(arguments[0]);

switch (typeof (arguments[0])) {
case 'function':
return this.server.listen(listenCallback);
case 'function':
return this.server.listen(listenCallback);

case 'string':
if (isPipeName(arguments[0]))
return this.server.listen(arguments[0], listenCallback);
case 'string':
if (isPipeName(arguments[0]))
return this.server.listen(arguments[0], listenCallback);

throw new TypeError(arguments[0] + ' is not a named pipe');
throw new TypeError(arguments[0] + ' is not a named pipe');

case 'number':
var host = arguments[1];
return this.server.listen(arguments[0],
typeof (host) === 'string' ? host : '0.0.0.0',
listenCallback);
case 'number':
var host = arguments[1];
return this.server.listen(arguments[0],
typeof (host) === 'string' ? host : '0.0.0.0',
listenCallback);

default:
throw new TypeError('port (Number) required');
default:
throw new TypeError('port (Number) required');
}

};
Expand Down Expand Up @@ -592,11 +594,11 @@ Server.prototype._findRoute = function _findRoute(req, res) {
* @param {Function} The middleware function to execute
*/
Server.prototype.param = function param(name, fn) {
return this.use(function (req, res, next) {
var value = req.params && req.params[name];
if (value)
return fn.call(this, req, res, next, value, name);
return this.use(function (req, res, next) {
var value = req.params && req.params[name];
if (value)
return fn.call(this, req, res, next, value, name);

return next();
});
return next();
});
};
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@
"Jonathan Wiepert",
"Mike Williams"
],
"name": "restify",
"name": "@chaordic/restify",
"homepage": "http://mcavage.github.com/node-restify",
"description": "REST framework",
"version": "1.4.4",
"version": "1.5.2-rc.1",
"repository": {
"type": "git",
"url": "git://github.com/mcavage/node-restify.git"
"url": "git://github.com/chaordic/node-restify.git"
},
"main": "lib/index.js",
"publishConfig": {
"@chaordic:registry": "https://npm.pkg.github.com"
},
"bin": {
"report-latency": "./bin/report-latency"
},
Expand Down