-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstackblitz
More file actions
58 lines (45 loc) · 1.75 KB
/
stackblitz
File metadata and controls
58 lines (45 loc) · 1.75 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<style>
html {height:100%}
body{height:calc(100% - 16px)}
embed{height:100%}
</style>
<div id=embed></div>
<script type=module>
/*
https://developer.stackblitz.com/platform/api/javascript-sdk
https://developer.stackblitz.com/platform/api/javascript-sdk-options
*/
import sdk from 'https://cdn.jsdelivr.net/npm/@stackblitz/sdk/+esm';
var files = {};
setup();
var project = {
title : 'Dynamically Generated Project',
description : 'Created with <3',
template : 'node',
files : files
};
var vm = await sdk.embedProject('embed',project,{
forceEmbedLayout : true,
openFile : 'index.html',
theme : 'light',
hideExplorer : true,
hideNavigation : false,
width : '100%',
height : '100%',
terminalHeight : '50',
view : 'default'
});
function setup(){
files['index.html'] = `<h1>SDK generated project</h1><script src=index.js></scri`+`pt>`;
files['index.js'] = `alert('helloworld')`;
files['package.json'] = `{"scripts":{"start":"node server"}}`;
files['server.js'] = `
require('http').createServer(request).listen(8000);
console.log('listening 8000');
function request(req,res){
res.writeHead(200,{'content-type':'text/html'});
res.end(require('fs').readFileSync('index.html','utf8'));
}//request
`;
}//setup
</script>