|
|
@@ -1,6 +1,6 @@
|
|
|
/**
|
|
|
- * Main application file
|
|
|
- */
|
|
|
+* Main application file
|
|
|
+*/
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
@@ -16,6 +16,26 @@ app.get('/', function (req, res) {
|
|
|
res.send('Hello World!')
|
|
|
})
|
|
|
|
|
|
-app.listen(3000, function () {
|
|
|
- console.log('Example app listening on port 3000!')
|
|
|
-})
|
|
|
+function allowCrossDomain(req, res, next) {
|
|
|
+ res.header('Access-Control-Allow-Origin', '*');
|
|
|
+ res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
|
|
|
+ res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With');
|
|
|
+
|
|
|
+ // intercept OPTIONS method
|
|
|
+ if ('OPTIONS' === req.method) {
|
|
|
+ res.send(200);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ next();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+app.use(allowCrossDomain);
|
|
|
+
|
|
|
+try {
|
|
|
+ app.listen(3000, function () {
|
|
|
+ console.log('Example app listening on port 3000!')
|
|
|
+ })
|
|
|
+} catch (error) {
|
|
|
+ console.error(error);
|
|
|
+}
|