Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // to start use:
- // sudo pm2 start ~/nodejs_apps/inwx.json
- // to delete from pm2 use:
- // sudo pm2 delete inwx
- // to view logs:
- // sudo pm2 inwx
- var express = require("express");
- var http = require('http'); // http server
- var app = express();
- var bodyParser = require("body-parser");
- var request = require('request');
- app.use(bodyParser.urlencoded({ extended: false })); // parse application/x-www-form-urlencoded
- app.use(bodyParser.json()); // parse application/json
- // https://github.com/mattes/inwx-nodejs
- var inwx = require('inwx');
- app.use(function(req, res, next) {
- log(req.protocol + ": " + req.method + " " + req.originalUrl /*+ "\n body = " + JSON.stringify(req.body)*/); // do not log body because it can get huge
- res.header('Access-Control-Allow-Origin', '*');
- res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS'); // OPTIONS?
- res.header('Access-Control-Allow-Headers', 'Accept, Accept-CH, Accept-Charset, Accept-Datetime, Accept-Encoding, Accept-Ext, Accept-Features, Accept-Language, Accept-Params, Accept-Ranges, Access-Control-Allow-Credentials, Access-Control-Allow-Headers, Access-Control-Allow-Methods, Access-Control-Allow-Origin, Access-Control-Expose-Headers, Access-Control-Max-Age, Access-Control-Request-Headers, Access-Control-Request-Method, Age, Allow, Alternates, Authentication-Info, Authorization, C-Ext, C-Man, C-Opt, C-PEP, C-PEP-Info, CONNECT, Cache-Control, Compliance, Connection, Content-Base, Content-Disposition, Content-Encoding, Content-ID, Content-Language, Content-Length, Content-Location, Content-MD5, Content-Range, Content-Script-Type, Content-Security-Policy, Content-Style-Type, Content-Transfer-Encoding, Content-Type, Content-Version, Cookie, Cost, DAV, DELETE, DNT, DPR, Date, Default-Style, Delta-Base, Depth, Derived-From, Destination, Differential-ID, Digest, ETag, Expect, Expires, Ext, From, GET, GetProfile, HEAD, HTTP-date, Host, IM, If, If-Match, If-Modified-Since, If-None-Match, If-Range, If-Unmodified-Since, Keep-Alive, Label, Last-Event-ID, Last-Modified, Link, Location, Lock-Token, MIME-Version, Man, Max-Forwards, Media-Range, Message-ID, Meter, Negotiate, Non-Compliance, OPTION, OPTIONS, OWS, Opt, Optional, Ordering-Type, Origin, Overwrite, P3P, PEP, PICS-Label, POST, PUT, Pep-Info, Permanent, Position, Pragma, ProfileObject, Protocol, Protocol-Query, Protocol-Request, Proxy-Authenticate, Proxy-Authentication-Info, Proxy-Authorization, Proxy-Features, Proxy-Instruction, Public, RWS, Range, Referer, Refresh, Resolution-Hint, Resolver-Location, Retry-After, Safe, Sec-Websocket-Extensions, Sec-Websocket-Key, Sec-Websocket-Origin, Sec-Websocket-Protocol, Sec-Websocket-Version, Security-Scheme, Server, Set-Cookie, Set-Cookie2, SetProfile, SoapAction, Status, Status-URI, Strict-Transport-Security, SubOK, Subst, Surrogate-Capability, Surrogate-Control, TCN, TE, TRACE, Timeout, Title, Trailer, Transfer-Encoding, UA-Color, UA-Media, UA-Pixels, UA-Resolution, UA-Windowpixels, URI, Upgrade, User-Agent, Variant-Vary, Vary, Version, Via, Viewport-Width, WWW-Authenticate, Want-Digest, Warning, Width, X-Content-Duration, X-Content-Security-Policy, X-Content-Type-Options, X-CustomHeader, X-DNSPrefetch-Control, X-Forwarded-For, X-Forwarded-Port, X-Forwarded-Proto, X-Frame-Options, X-Modified, X-OTHER, X-PING, X-PINGOTHER, X-Powered-By, X-Requested-With');
- res.header("Content-Type", "application/json; charset=utf-8");
- next();
- });
- app.get("/inwx", function (req, res) {
- var rc = {};
- rc.request = req.method + " " + req.originalUrl;
- rc.request_body = req.body;
- // set api to production or testing
- inwx({api: "production", user: "myusername", password: "mypassword"}, function(api){
- log("API is ready"); // NEVER SHOWN!!!
- // get account infos
- api.call("account", "info", {}, function(response){
- var msg = "account.info response:" + response;
- rc.message = msg;
- log(msg); // NEVER SHOWN!!!
- api.close();
- rc.status = 200;
- res.status(200);
- res.send(rc);
- });
- // SOA serial numbers are updated by INWX automatically!
- // be aware that calls are made asynchronously! call api.close() when all other calls terminated.
- // api.close(); // logout
- });
- });
- app.options("*", function (req, res) {
- log(req.method + " " + req.originalUrl);
- res.send("GET, POST, PUT, DELETE");
- });
- var listenerHTTP = http.createServer(app).listen(6012, function () {
- log("HTTP: app listening on port " + listenerHTTP.address().port + "!");
- });
- function log(msg) {
- var d = new Date();
- console.log(d.toISOString() + " inwx: " + msg);
- }
- function logerror(msg) {
- var d = new Date();
- console.error(d.toISOString() + " inwx: Error! " + msg);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement