| 96 | } |
| 97 | |
| 98 | function createExpressApp() { |
| 99 | let filepath = config.path; |
| 100 | const app = express(); |
| 101 | |
| 102 | app.use(bodyParser.json()); |
| 103 | app.use(bodyParser.urlencoded({extended: true})); |
| 104 | |
| 105 | app.get("/build/workspaces.js", (request, response) => { |
| 106 | let packaged = eveSource.pack(); |
| 107 | response.setHeader("Content-Type", `application/javascript; charset=utf-8`); |
| 108 | response.end(packaged); |
| 109 | }); |
| 110 | |
| 111 | app.get("/assets/*", handleStatic); |
| 112 | app.get("/build/*", handleStatic); |
| 113 | |
| 114 | app.get("*", (request, response) => { |
| 115 | let client; |
| 116 | // @FIXME: When Owner.both is added this needs updated. |
| 117 | if(config.runtimeOwner === Owner.server) { |
| 118 | client = new HTTPRuntimeClient(); |
| 119 | let content = ""; |
| 120 | if(filepath) content = fs.readFileSync(filepath).toString(); |
| 121 | client.load(content, "user"); |
| 122 | client.handle(request, response); |
| 123 | } |
| 124 | if(config.runtimeOwner === Owner.client || client && !client.server.handling) { |
| 125 | response.setHeader("Content-Type", `${contentTypes["html"]}; charset=utf-8`); |
| 126 | response.end(fs.readFileSync(path.join(config.eveRoot, "index.html"))); |
| 127 | } |
| 128 | }); |
| 129 | |
| 130 | app.post("*", (request, response) => { |
| 131 | let client; |
| 132 | // @FIXME: When Owner.both is added this needs updated. |
| 133 | if(config.runtimeOwner === Owner.server) { |
| 134 | client = new HTTPRuntimeClient(); |
| 135 | let content = ""; |
| 136 | if(filepath) content = fs.readFileSync(filepath).toString(); |
| 137 | client.load(content, "user"); |
| 138 | client.handle(request, response); |
| 139 | } |
| 140 | if(config.runtimeOwner === Owner.client || client && !client.server.handling) { |
| 141 | return response.status(404).send("Looks like that asset is missing."); |
| 142 | } |
| 143 | }); |
| 144 | |
| 145 | return app; |
| 146 | } |
| 147 | |
| 148 | //--------------------------------------------------------------------- |
| 149 | // Websocket |