Created
March 31, 2016 19:19
-
-
Save alfonsogarciacaro/36464766b0707b83ab13038aca580d7c to your computer and use it in GitHub Desktop.
Fable/samples/browser/react
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
var _models = require("./models"); | |
var _models2 = _interopRequireDefault(_models); | |
var _fs = require("fs"); | |
var $M4 = _interopRequireWildcard(_fs); | |
var _path = require("path"); | |
var $M3 = _interopRequireWildcard(_path); | |
var _express = require("express"); | |
var _express2 = _interopRequireDefault(_express); | |
var _fableCore = require("./fable-core"); | |
var $M1 = _interopRequireWildcard(_fableCore); | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |
exports.default = function ($M0) { | |
var matchValue, x; | |
var Util = $M0.Util = function ($M0) { | |
var handleError = $M0.handleError = function (onErr, onSuccess, err) { | |
var err_1; | |
var matchValue = err; | |
matchValue == null ? onSuccess() : (err_1 = matchValue, onErr(err_1)); | |
}; | |
var failExit = $M0.failExit = function (err) { | |
console.log($M1.String.format(err.toString())); | |
process.exit(1); | |
}; | |
return $M0; | |
}({}); | |
var port = $M0.port = (matchValue = process.env.PORT, matchValue == null ? 8080 : (x = matchValue, x)); | |
var appPort = $M0.appPort = port; | |
var app = $M0.app = (0, _express2.default)(); | |
var COMMENTS_FILE = $M0.COMMENTS_FILE = $M3.join(process.cwd(), "comments.json"); | |
var bodyParser = $M0.bodyParser = require("body-parser"); | |
(function (arg00) { | |
return app.use(arg00); | |
})(bodyParser.json()); | |
(function (arg00) { | |
return app.use(arg00); | |
})(bodyParser.urlencoded({ | |
extended: true | |
})); | |
(function (sta) { | |
return app.use("/", sta); | |
})(function () { | |
var objectArg; | |
return objectArg = _express2.default.static, function (arg00) { | |
return objectArg(arg00); | |
}; | |
}()($M3.join(process.cwd(), "public"))); | |
app.use(function (req, res, next) { | |
return res.setHeader("Access-Control-Allow-Origin", "*"), res.setHeader("Cache-Control", "no-cache"), function (arg00) { | |
next(arg00); | |
}(); | |
}); | |
app.get("/api/comments/", function (req, res, _arg1) { | |
return $M4.readFile(COMMENTS_FILE, function (err, data) { | |
(function () { | |
var onSuccess; | |
return onSuccess = function (unitVar0) { | |
return res.json(function () { | |
var objectArg; | |
return objectArg = JSON, function (arg00) { | |
return objectArg.parse(arg00); | |
}; | |
}()(data.toString())); | |
}, function (err_1) { | |
Util.handleError(Util.failExit, onSuccess, err_1); | |
}; | |
})()(err); | |
}); | |
}); | |
app.post("/api/comments/", function (req, res, _arg2) { | |
return $M4.readFile(COMMENTS_FILE, function (err, data) { | |
(function () { | |
var onSuccess; | |
return onSuccess = function (unitVar0) { | |
var objectArg; | |
var comments = function () { | |
var objectArg; | |
return objectArg = JSON, function (arg00) { | |
return objectArg.parse(arg00); | |
}; | |
}()(data.toString()); | |
comments.push(new _models2.default.Comment($M1.Date.now(), req.body.author.toString(), req.body.text.toString())); | |
$M4.writeFile(COMMENTS_FILE, (objectArg = JSON, function (arg00) { | |
return objectArg.stringify(arg00); | |
})(comments, null, 4), function (err_1) { | |
(function () { | |
var onSuccess; | |
return onSuccess = function (unitVar0_1) { | |
return res.json(comments); | |
}, function (err_2) { | |
Util.handleError(Util.failExit, onSuccess, err_2); | |
}; | |
})()(err_1); | |
}); | |
}, function (err_1) { | |
Util.handleError(Util.failExit, onSuccess, err_1); | |
}; | |
})()(err); | |
}); | |
}); | |
app.listen(appPort, function (unitVar0) { | |
(function () { | |
var clo1; | |
return clo1 = $M1.String.fsFormat("API server started: http://localhost:%i/")(function (x) { | |
console.log(x); | |
}), function (arg10) { | |
clo1(arg10); | |
}; | |
})()(appPort); | |
}); | |
return $M0; | |
}({}); | |
module.exports = exports['default']; | |
//# sourceMappingURL=server.js.map |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment