celia
1/10/2018 - 3:52 PM

NodeJS - Static files server

var express = require('express');
var app = express();
var path = require('path');

// Define the port to run on
app.set('port', 5000);
app.use(express.static(path.join(__dirname, 'src/sandos_iframe')));

app.use((req, res, next) => {
  res.header('Access-Control-Allow-Origin', '*');
  res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
  next();
});

// Listen for requests
var server = app.listen(app.get('port'), function() {
  var port = server.address().port;
	console.log('Magic happens on port ' + port);
});
const express = require('express');
const app = express();
const path = require('path');

// Define the port to run on
app.set('port', 5000);
app.use(express.static(path.join(__dirname, 'src/sandos_iframe')));

app.use((req, res, next) => {
  res.header('Access-Control-Allow-Origin', '*');
  res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
  next();
});

// Listen for requests
const server = app.listen(app.get('port'), function() {
  const port = server.address().port;
	console.log('Magic happens on port ' + port);
});

const express = require('express');
const cors = require('cors');
const app = express();

const corsOptions = {
  origin: process.env.CORS_ALLOW_ORIGIN || '*',
  methods: ['GET', 'PUT', 'POST', 'DELETE', 'OPTIONS'],
  allowedHeaders: ['Content-Type', 'Authorization'],
};

// Define the port to run on
app.set('port', 5000);

app.use(cors(corsOptions));
app.use(express.static('app'));

// Listen for requests
const server = app.listen(app.get('port'), function() {
  const { port } = server.address();
  console.log(`Magic happens on port ${port}`);
});