add embed route, fix path parsing in PreviewFrame
This commit is contained in:
parent
8d20aa3d97
commit
207bab20eb
6 changed files with 166 additions and 31 deletions
98
cert_chain.crt
Normal file
98
cert_chain.crt
Normal file
|
@ -0,0 +1,98 @@
|
||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIIFYzCCBEugAwIBAgIQA6rbgXGYPzeo4y0pZyTW3zANBgkqhkiG9w0BAQsFADCB
|
||||||
|
kDELMAkGA1UEBhMCR0IxGzAZBgNVBAgTEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4G
|
||||||
|
A1UEBxMHU2FsZm9yZDEaMBgGA1UEChMRQ09NT0RPIENBIExpbWl0ZWQxNjA0BgNV
|
||||||
|
BAMTLUNPTU9ETyBSU0EgRG9tYWluIFZhbGlkYXRpb24gU2VjdXJlIFNlcnZlciBD
|
||||||
|
QTAeFw0xNjA5MDUwMDAwMDBaFw0xNzA5MDMyMzU5NTlaMFkxITAfBgNVBAsTGERv
|
||||||
|
bWFpbiBDb250cm9sIFZhbGlkYXRlZDEUMBIGA1UECxMLUG9zaXRpdmVTU0wxHjAc
|
||||||
|
BgNVBAMTFWFscGhhLmVkaXRvci5wNWpzLm9yZzCCASIwDQYJKoZIhvcNAQEBBQAD
|
||||||
|
ggEPADCCAQoCggEBAKfMrXVqIeItu+uQKdUcx5ytGWwdIpFpYVsoS5Y2ewqf7r+q
|
||||||
|
v+npJGdp37ebOJ4itV3RArU/erUAaPDAFs7S+37HtDALAwcCdg5/ZSGh52QLsLQu
|
||||||
|
p+aW3eVgidmFtaQj2NuDud5uaHw/weTe4c9UPxtzt6sg65iPcjtnSmRnoqvNrYGi
|
||||||
|
qYdgZ+ggBiEtyyyHWb++okRmzkkaC3I3+YtEElSPNMKoPximzbVdGoUu4BsIHBnk
|
||||||
|
u/gY6xinmeg+SOo/BpM59/pKsVPKBk+DAtm+OK/pi2scsrnd3cv+Cfzzku/2sBlu
|
||||||
|
yuDndSKzfqvZnLQ8oN7ZwGXK9yz1x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tKyPQaFx+SH4i3v1u2fyfIslk7t072z7Xnl7K3i1qUDLUKssLgMcJY
|
||||||
|
AOpA7BEBaPfV06px0K5RLCp2tLLuU2kedrHqx4LCYNxuB7HbSdTD
|
||||||
|
-----END CERTIFICATE-----
|
||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIIGCDCCA/CgAwIBAgIQKy5u6tl1NmwUim7bo3yMBzANBgkqhkiG9w0BAQwFADCB
|
||||||
|
hTELMAkGA1UEBhMCR0IxGzAZBgNVBAgTEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4G
|
||||||
|
A1UEBxMHU2FsZm9yZDEaMBgGA1UEChMRQ09NT0RPIENBIExpbWl0ZWQxKzApBgNV
|
||||||
|
BAMTIkNPTU9ETyBSU0EgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMTQwMjEy
|
||||||
|
MDAwMDAwWhcNMjkwMjExMjM1OTU5WjCBkDELMAkGA1UEBhMCR0IxGzAZBgNVBAgT
|
||||||
|
EkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4GA1UEBxMHU2FsZm9yZDEaMBgGA1UEChMR
|
||||||
|
Q09NT0RPIENBIExpbWl0ZWQxNjA0BgNVBAMTLUNPTU9ETyBSU0EgRG9tYWluIFZh
|
||||||
|
bGlkYXRpb24gU2VjdXJlIFNlcnZlciBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEP
|
||||||
|
ADCCAQoCggEBAI7CAhnhoFmk6zg1jSz9AdDTScBkxwtiBUUWOqigwAwCfx3M28Sh
|
||||||
|
bXcDow+G+eMGnD4LgYqbSRutA776S9uMIO3Vzl5ljj4Nr0zCsLdFXlIvNN5IJGS0
|
||||||
|
Qa4Al/e+Z96e0HqnU4A7fK31llVvl0cKfIWLIpeNs4TgllfQcBhglo/uLQeTnaG6
|
||||||
|
ytHNe+nEKpooIZFNb5JPJaXyejXdJtxGpdCsWTWM/06RQ1A/WZMebFEh7lgUq/51
|
||||||
|
UHg+TLAchhP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wYBBQUHMAGGGWh0dHA6
|
||||||
|
Ly9vY3NwLnVzZXJ0cnVzdC5jb20wDQYJKoZIhvcNAQEMBQADggEBAGS/g/FfmoXQ
|
||||||
|
zbihKVcN6Fr30ek+8nYEbvFScLsePP9NDXRqzIGCJdPDoCpdTPW6i6FtxFQJdcfj
|
||||||
|
Jw5dhHk3QBN39bSsHNA7qxcS1u80GH4r6XnTq1dFDK8o+tDb5VCViLvfhVdpfZLY
|
||||||
|
Uspzgb8c8+a4bmYRBbMelC1/kZWSWfFMzqORcUx8Rww7Cxn2obFshj5cqsQugsv5
|
||||||
|
B5a6SE2Q8pTIqXOi6wZ7I53eovNNVZ96YUWYGGjHXkBrI/V5eu+MtWuLt29G9Hvx
|
||||||
|
PUsE2JOAWVrgQSQdso8VYFhH2+9uRv0V9dlfmrPb2LjkQLPNlzmuhbsdjrzch5vR
|
||||||
|
pu/xO28QOG8=
|
||||||
|
-----END CERTIFICATE-----
|
|
@ -1,24 +0,0 @@
|
||||||
import React, { PropTypes } from 'react';
|
|
||||||
|
|
||||||
class Preview extends React.Component {
|
|
||||||
componentDidMount() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.0/p5.min.js"></script>
|
|
||||||
<script type="text/javascript">
|
|
||||||
{this.props.content}
|
|
||||||
</script>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Preview.propTypes = {
|
|
||||||
content: PropTypes.string.isRequired
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Preview;
|
|
|
@ -148,6 +148,7 @@ class PreviewFrame extends React.Component {
|
||||||
// one level down...
|
// one level down...
|
||||||
|
|
||||||
htmlFile = hijackConsoleLogsScript() + htmlFile;
|
htmlFile = hijackConsoleLogsScript() + htmlFile;
|
||||||
|
const mediaFiles = this.props.files.filder(file => file.url);
|
||||||
|
|
||||||
const jsFiles = [];
|
const jsFiles = [];
|
||||||
this.props.jsFiles.forEach(jsFile => {
|
this.props.jsFiles.forEach(jsFile => {
|
||||||
|
@ -158,13 +159,9 @@ class PreviewFrame extends React.Component {
|
||||||
jsFileStrings.forEach(jsFileString => {
|
jsFileStrings.forEach(jsFileString => {
|
||||||
if (jsFileString.match(jsFileRegex)) {
|
if (jsFileString.match(jsFileRegex)) {
|
||||||
const filePath = jsFileString.substr(1, jsFileString.length - 2);
|
const filePath = jsFileString.substr(1, jsFileString.length - 2);
|
||||||
let fileName = filePath;
|
const filePathArray = filePath.split('/');
|
||||||
if (fileName.match(/^\.\//)) {
|
const fileName = filePathArray[filePathArray.length - 1];
|
||||||
fileName = fileName.substr(2, fileName.length - 1);
|
mediaFiles.forEach(file => {
|
||||||
} else if (fileName.match(/^\//)) {
|
|
||||||
fileName = fileName.substr(1, fileName.length - 1);
|
|
||||||
}
|
|
||||||
this.props.files.forEach(file => {
|
|
||||||
if (file.name === fileName) {
|
if (file.name === fileName) {
|
||||||
newJSFile.content = newJSFile.content.replace(filePath, file.blobURL); // eslint-disable-line
|
newJSFile.content = newJSFile.content.replace(filePath, file.blobURL); // eslint-disable-line
|
||||||
}
|
}
|
||||||
|
|
53
server/controllers/embed.controller.js
Normal file
53
server/controllers/embed.controller.js
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
import Project from '../models/project';
|
||||||
|
import escapeStringRegexp from 'escape-string-regexp';
|
||||||
|
const startTag = '@fs-';
|
||||||
|
|
||||||
|
function injectMediaUrls(filesToInject, mediaFiles) {
|
||||||
|
filesToInject.forEach(file => {
|
||||||
|
let fileStrings = file.content.match(/(['"])((\\\1|.)*?)\1/gm);
|
||||||
|
const fileStringRegex = /^('|")(?!(http:\/\/|https:\/\/)).*('|")$/i;
|
||||||
|
fileStrings = fileStrings || [];
|
||||||
|
fileStrings.forEach(fileString => {
|
||||||
|
//if string does not begin with http or https
|
||||||
|
if (fileString.match(fileStringRegex)) {
|
||||||
|
const filePath = fileString.substr(1, fileString.length - 2);
|
||||||
|
const filePathArray = filePath.split('/');
|
||||||
|
const fileName = filePathArray[filePathArray.length - 1];
|
||||||
|
mediaFiles.forEach(mediaFile => {
|
||||||
|
if (mediaFile.name === fileName) {
|
||||||
|
file.content = file.content.replace(filePath, mediaFile.url);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function serveProject(req, res) {
|
||||||
|
Project.findById(req.params.project_id)
|
||||||
|
.exec((err, project) => {
|
||||||
|
const files = project.files;
|
||||||
|
let htmlFile = files.find(file => file.name.match(/\.html$/i)).content;
|
||||||
|
const jsFiles = files.filter(file => file.name.match(/\.js$/i));
|
||||||
|
const cssFiles = files.filter(file => file.name.match(/\.css$/i));
|
||||||
|
const mediaFiles = files.filter(file => file.url);
|
||||||
|
|
||||||
|
injectMediaUrls(jsFiles, mediaFiles);
|
||||||
|
injectMediaUrls(cssFiles, mediaFiles);
|
||||||
|
|
||||||
|
jsFiles.forEach(jsFile => {
|
||||||
|
const fileName = escapeStringRegexp(jsFile.name);
|
||||||
|
const fileRegex = new RegExp(`<script.*?src=('|")((\.\/)|\/)?${fileName}('|").*?>([\s\S]*?)<\/script>`, 'gmi');
|
||||||
|
const replacementString = `<script data-tag="${startTag}${jsFile.name}">\n${jsFile.content}\n</script>`;
|
||||||
|
htmlFile = htmlFile.replace(fileRegex, replacementString);
|
||||||
|
});
|
||||||
|
|
||||||
|
cssFiles.forEach(cssFile => {
|
||||||
|
const fileName = escapeStringRegexp(cssFile.name);
|
||||||
|
const fileRegex = new RegExp(`<link.*?href=('|")((\.\/)|\/)?${fileName}('|").*?>`, 'gmi');
|
||||||
|
htmlFile = htmlFile.replace(fileRegex, `<style>\n${cssFile.content}\n</style>`);
|
||||||
|
});
|
||||||
|
|
||||||
|
res.send(htmlFile);
|
||||||
|
});
|
||||||
|
}
|
8
server/routes/embed.routes.js
Normal file
8
server/routes/embed.routes.js
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
import { Router } from 'express';
|
||||||
|
import * as EmbedController from '../controllers/embed.controller';
|
||||||
|
|
||||||
|
const router = new Router();
|
||||||
|
|
||||||
|
router.route('/embed/:project_id').get(EmbedController.serveProject);
|
||||||
|
|
||||||
|
export default router;
|
|
@ -30,6 +30,7 @@ import projects from './routes/project.routes';
|
||||||
import files from './routes/file.routes';
|
import files from './routes/file.routes';
|
||||||
import aws from './routes/aws.routes';
|
import aws from './routes/aws.routes';
|
||||||
import serverRoutes from './routes/server.routes';
|
import serverRoutes from './routes/server.routes';
|
||||||
|
import embedRoutes from './routes/embed.routes';
|
||||||
|
|
||||||
// Body parser, cookie parser, sessions, serve public assets
|
// Body parser, cookie parser, sessions, serve public assets
|
||||||
|
|
||||||
|
@ -62,6 +63,8 @@ app.use('/api', aws);
|
||||||
// this is supposed to be TEMPORARY -- until i figure out
|
// this is supposed to be TEMPORARY -- until i figure out
|
||||||
// isomorphic rendering
|
// isomorphic rendering
|
||||||
app.use('/', serverRoutes);
|
app.use('/', serverRoutes);
|
||||||
|
|
||||||
|
app.use('/', embedRoutes);
|
||||||
app.get('/auth/github', passport.authenticate('github'));
|
app.get('/auth/github', passport.authenticate('github'));
|
||||||
app.get('/auth/github/callback', passport.authenticate('github', { failureRedirect: '/login' }), (req, res) => {
|
app.get('/auth/github/callback', passport.authenticate('github', { failureRedirect: '/login' }), (req, res) => {
|
||||||
res.redirect('/');
|
res.redirect('/');
|
||||||
|
|
Loading…
Reference in a new issue