Initial release of Google Opal AI iOS Web Studio
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
const http = require('http');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const os = require('os');
|
||||
|
||||
const PORT = 8080;
|
||||
const DIRECTORY = __dirname;
|
||||
|
||||
const MIME_TYPES = {
|
||||
'.html': 'text/html; charset=UTF-8',
|
||||
'.css': 'text/css',
|
||||
'.js': 'application/javascript',
|
||||
'.json': 'application/json',
|
||||
'.png': 'image/png',
|
||||
'.jpg': 'image/jpeg',
|
||||
'.jpeg': 'image/jpeg',
|
||||
'.svg': 'image/svg+xml',
|
||||
'.ico': 'image/x-icon'
|
||||
};
|
||||
|
||||
function getLocalIp() {
|
||||
const interfaces = os.networkInterfaces();
|
||||
for (const name of Object.keys(interfaces)) {
|
||||
for (const iface of interfaces[name]) {
|
||||
if (iface.family === 'IPv4' && !iface.internal) {
|
||||
return iface.address;
|
||||
}
|
||||
}
|
||||
}
|
||||
return '127.0.0.1';
|
||||
}
|
||||
|
||||
const server = http.createServer((req, res) => {
|
||||
let reqPath = req.url.split('?')[0];
|
||||
if (reqPath === '/' || reqPath === '') reqPath = '/index.html';
|
||||
|
||||
const filePath = path.join(DIRECTORY, reqPath);
|
||||
const ext = path.extname(filePath).toLowerCase();
|
||||
const contentType = MIME_TYPES[ext] || 'application/octet-stream';
|
||||
|
||||
fs.readFile(filePath, (err, content) => {
|
||||
if (err) {
|
||||
if (err.code === 'ENOENT') {
|
||||
res.writeHead(404, { 'Content-Type': 'text/plain' });
|
||||
res.end('404 Not Found');
|
||||
} else {
|
||||
res.writeHead(500, { 'Content-Type': 'text/plain' });
|
||||
res.end(`Server Error: ${err.code}`);
|
||||
}
|
||||
} else {
|
||||
res.writeHead(200, {
|
||||
'Content-Type': contentType,
|
||||
'Access-Control-Allow-Origin': '*'
|
||||
});
|
||||
res.end(content);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
server.listen(PORT, '0.0.0.0', () => {
|
||||
const localIp = getLocalIp();
|
||||
console.log('='.repeat(60));
|
||||
console.log('💎 Google Opal AI - iOS Web Studio is Live & Running!');
|
||||
console.log('='.repeat(60));
|
||||
console.log(`📱 Open on your iPhone Safari (connected to same Wi-Fi):`);
|
||||
console.log(` 👉 http://${localIp}:${PORT}`);
|
||||
console.log(`💻 Or on PC Browser: http://localhost:${PORT}`);
|
||||
console.log('='.repeat(60));
|
||||
console.log('💡 iPhone Instruction: Safari-তে গিয়ে "Share ➔ Add to Home Screen" দিন।');
|
||||
console.log('='.repeat(60));
|
||||
});
|
||||
Reference in New Issue
Block a user