-
Notifications
You must be signed in to change notification settings - Fork 190
/
metro.config.js
44 lines (43 loc) · 1.28 KB
/
metro.config.js
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
// Learn more https://docs.expo.io/guides/customizing-metro
const path = require('path');
const fs = require('fs');
const { mergeConfig } = require('metro-config');
const { getDefaultConfig } = require('@react-native/metro-config');
const defaultConfig = getDefaultConfig(__dirname);
const map = {
'.ico': 'image/x-icon',
'.html': 'text/html',
'.js': 'text/javascript',
'.json': 'application/json',
'.css': 'text/css',
'.png': 'image/png',
'.jpg': 'image/jpeg',
};
const customConfig = {
server: {
port: 8081,
enhanceMiddleware: (metroMiddleware, metroServer) => {
return (request, res, next) => {
const filePath = path.join(
__dirname,
'android/app/src/main',
request._parsedUrl.path || '',
);
const ext = path.parse(filePath).ext;
if (fs.existsSync(filePath)) {
try {
const data = fs.readFileSync(filePath);
res.setHeader('Content-type', map[ext] || 'text/plain');
res.end(data);
} catch (err) {
res.statusCode = 500;
res.end(`Error getting the file: ${err}.`);
}
} else {
return metroMiddleware(request, res, next);
}
};
},
},
};
module.exports = mergeConfig(defaultConfig, customConfig);