File size: 927 Bytes
a548ebc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
'use strict'

// Define the basic imports and constants.
const express = require('express');
const app = express();
const embeddedApp = express();
const port = 3000;
const embeddedPort = 3001;

// Setup the outside app with the www folder as static content.
app.use(express.static('www'));

// Create the outside app and run it.
app.listen(port, () => {
  console.log(`Open browser to http://localhost:${port}/ to begin.`);
});

// Create the embedded app with the www2 folder as static content and
// set the cookie from the embedded app in the headers on all requests.
embeddedApp.use(express.static('www2', {
  setHeaders: function (res, path, stat) {
    res.set('Set-Cookie', "embeddedCookie=Hello from an embedded third party cookie!;Path=/;Secure;SameSite=None");
  }
}));

// Create the server and start it.
embeddedApp.listen(embeddedPort, () => {
  console.log(`Embedded server now running on ${embeddedPort}...`)
});